note 35264 deleted from function.readdir by vincent

From: Date: Tue, 26 Aug 2003 09:58:18 +0000
Subject: note 35264 deleted from function.readdir by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55091@lists.php.net to get a copy of this message
Note Submitter: ian9002001@yahoo.com ---- i have a program that reads the dir and lets you uploaf files! Please note... the upload uses ftp functions... and does not work if FTP_ is disabled. <?php echo "Automatic Directory File Listing: V.1<br><hr>\n"; echo "<br>Files:<br>\n"; ?> <table align="center" width="100%" border=0> <tr> <td bgcolor="#DDDDDD">File Name</td><td bgcolor="#EEEEEE">File Type</td><td>File Size</td> </tr> <?php if ($handle = opendir('./')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $size = filesize($file); $type = filetype($file); $location = "./$file"; echo "<tr>\n"; echo "<td bgcolor=\"#DDDDDD\"><a href=\"$location\">$file</a></td><td bgcolor=\"#EEEEEE\"> $type </td><td> $size </td>\n"; echo "</tr>\n"; } } closedir($handle); } ?> <tr> <td> <? // set to 1 to turn on uploading... set to 0 to turn off uploading. $upload_X = 0; function upload1() { $ftp_server='server';//serverip $conn_id = ftp_connect($ftp_server); // login with username and password $user="username"; $passwd="password"; $login_result = ftp_login($conn_id, $user, $passwd); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; die; } else { echo " Connected to $ftp_server, for user $user "; } //directorylike /www.velibaba.com/images ftp_chdir($conn_id, "./"); //$destination_file=ftp_pwd($conn_id); $destination_file = ftp_pwd($conn_id); echo (""); print $destination_file; echo (""); // upload the file $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); // check upload status if (!$upload) { echo "FTP upload has failed!"; } else { echo "Uploaded $source_file to $ftp_server as $destination_file"; } // close the FTP stream ftp_close($conn_id); } if ($upload_X == 1) { echo "<form method='post' action='".$PHP_SELF."'> <br>File Upload:<br> <input type=\"file\" name=\"source_file\" size=20> <input type=\"submit\" name=\"btnSubmit\" value=\"Submit\" size=20 style=\"border: 1px solid #0000FF\"> </form>"; } elseif ($upload_X == 0) { echo "<br>Upload Disabled"; } if(isset($_POST['source_file'])) { upload1(); } ?> </td> </tr> </table> it's almost buggless... but it works just fine. an example of this is like so: Automatic Directory Listing V.1 --------------------------------------------------------- File Name File Type File Size index.php file 40086 Upload Disabled if you want added security like: you cannot download this file. find this: if ($file != "." && $file != "..") and replace it with: if ($file != "." && $file != ".." && $file != "filename.php") that is all.

« previous php.notes (#55091) next »