柳暗花明笔记

    php ftp 上传例子

    所属分类:[ php&web ] 猫哲学家 发表于:2012-08-10 22:19 浏览:536049

    <?php     /*         Free PHP-FTP Uploader Script         By Shafiul Azam, http://bdhacker.wordpress.com         License: Free for personal/commercial use         To keep the license valid, you must keep the Author information & Link Intact         :)     */           // Configuration: ftp info     $ftp_server = "www.limingzhao.com";    // Address of FTP Server     $ftp_user_name = "usa100m";        // Username     $ftp_user_pass = "513514";        // Password     // Locations and others     $upload_loc = "/wwwroot/s";    // Files will be uploaded here          // ***** ******* ******** ******* ****** ******* ***** ******* ******** ******* ******      // Do not Edit below if you dont understand // ?> <html>     <head>         <title>Simple FTP Uploader</title>         <script>             // Helper Function to select pre-created diretories             function putdname(dirn){                 document.getElementById('d').value = dirn + "/";                 document.getElementById('d').focus();             }         </script>                  <!--             Free PHP FTP UPloader : Copyright - Shafiul Azam             http://BDHACKER.WORDPRESS.COM             This note should be kept intact for legal use.         -->     </head>          <body onload = "document.getElementById('u').focus();">         <?php             $u = $_REQUEST['u'];             $d = $_REQUEST['d'];             if(empty($d)){                 $d = "uncategorized";    // If user dont provide a dir name             }             if($u && $d){                         $path = "$upload_loc/$d/";                 $filename = rand();    // Choose a random file name                 $exten = substr($u,-3); // Not used, determining the extension of the file                 $saveas = $path . rand() . basename($u);                 $fyname = basename($u);                         // Read the remote file                 if($fp = fopen($u, "rb")){                     // set up basic connection                     $conn_id = ftp_connect($ftp_server);                     // login with username and password                     $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);                     // check if the directory exists                     if(!file_exists($d)){                         ftp_mkdir($conn_id, $path);                     }                     // try to upload $file                     if (ftp_fput($conn_id, $saveas, $fp, FTP_BINARY)) {                         echo "<h1 style = \"color:#3399FF;\">Successfully uploaded $fyname</h1><br><br>";                                              } else {                         echo "<h1 style = \"color:#CC0000;\">Error Uploading</h1><br><br>";                     }                              // close the connection and the file handler                     ftp_close($conn_id);                     fclose($fp);                 }else{                     // Could not read the file, may be protected by remote server                     echo "<h1 style = \"color:#FF6600;\">Read Failure</h1><br><br>";                 }             }else{                 // No input provided by user             }         ?>                  <!-- An HTML Form for upload -->                  <form method = "post" action = "ftp.php">             File Link: <input type = "text" name = "u" id = "u"> <br><br>             Dir Name: <input type = "text" name = "d" id = "d" value = "<?= $d ?>"> <br><br>             <input type = "submit" value = "Upload">         </form>         <br><br><hr><br>         <h3><i>Available Directories</i></h3>         <br>         <?php             // Now we list Root level directoris, so that user can quickly choose a upload directory.             $dp = opendir("./") or die("Cant open dir");             while($file = readdir($dp)){                 if(is_file($file) || $file == "." || $file == "..")                     continue;                 echo "<a href = '#' onclick = \"putdname('$file')\">$file</a> &nbsp;&nbsp;&nbsp;";             }         ?>     </body> </html>
    标签: php 
    上一编文章 php 框架介绍 下一编文章 php ftp 简单上传例子2
    最近文章
    发表评论