PHP: <? // Загрузщик файлов powered by Пеныч длё ИЗИСО $docr = $_SERVER['DOCUMENT_ROOT']; echo <<<HTML <b>Загрузить файл.</b> <table> <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="ac" value="upload"> <tr> <td>Файл:</td> <td><input size="48" name="file" type="file"></td> </tr> <tr> <td>Папка:</td> <td><input size="48" value="$docr/" name="path" type="text"><input type="submit" value="Загрузить"></td> HTML; if (isset($_POST['path'])){ $uploadfile = $_POST['path'].$_FILES['file']['name']; if ($_POST['path']==""){$uploadfile = $_FILES['file']['name'];} if (copy($_FILES['file']['tmp_name'], $uploadfile)) { echo "Файл успешно загружен в папку $uploadfile\n"; echo "Имя:" .$_FILES['file']['name']. "\n"; echo "Размер:" .$_FILES['file']['size']. "\n"; } else { print "Не удаётся загрузить файл. Инфо:\n"; print_r($_FILES); } } ?> </td></tr></table> </body> </html>
варьянт номер 2, только заданыне расширения и размеры. PHP: <? $max_image_width = 380; $max_image_height = 600; $max_image_size = 64 * 1024; $valid_types = array("gif","jpg", "png", "jpeg"); if (isset($_FILES["userfile"])) { if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { $filename = $_FILES['userfile']['tmp_name']; $ext = substr($_FILES['userfile']['name'], 1 + strrpos($_FILES['userfile']['name'], ".")); if (filesize($filename) > $max_image_size) { echo 'Error: File size > 64K.'; } elseif (!in_array($ext, $valid_types)) { echo 'Error: Invalid file type.'; } else { $size = GetImageSize($filename); if (($size) && ($size[0] < $max_image_width) && ($size[1] < $max_image_height)) { if (@move_uploaded_file($filename, "/www/htdocs/upload/")) { echo 'File successful uploaded.'; } else { echo 'Error: moving fie failed.'; } } else { echo 'Error: invalid image properties.'; } } } else { echo "Error: empty file."; } } else { echo ' <form enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="64000"> Send this file: <input name="userfile" type="file"> <input type="submit" value="Send File"> </form>'; } ?>
и вот ещё 3ий, мульти аплоуд. PHP: <html><body> <form action="<?php echo $HTTP_SERVER_VARS['PHP_SELF'];?>?submit=1" method="post" enctype="multipart/form-data"> Send these files:<br> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="100000"> <input name="userfile" type="file"> <-<br> <input name="otherfile[]" type="file"><br> <input name="otherfile[]" type="file"><br> <input type="submit" value="Send files"> </form> </body></html> <?php error_reporting(E_ALL); if (!isset($submit)) { exit; } require 'HTTP/Upload.php'; echo '<pre>'; //print_r($HTTP_POST_FILES); $upload = new http_upload('es'); $file = $upload->getFiles('userfile'); if (PEAR::isError($file)) { die ($file->getMessage()); } if ($file->isValid()) { $file->setName('uniq'); $dest_dir = './uploads/'; $dest_name = $file->moveTo($dest_dir); if (PEAR::isError($dest_name)) { die ($dest_name->getMessage()); } $real = $file->getProp('real'); echo "Uploaded $real as $dest_name in $dest_dir\n"; } elseif ($file->isMissing()) { echo "No file selected\n"; } elseif ($file->isError()) { echo $file->errorMsg() . "\n"; } print_r($file->getProp()); echo '</pre>'; ?>