- -. . , , , . PHP move uploaded file.
PHP POST. , HTML-. , . , . .
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" id="signup_form" enctype="multipart/form-data"> <fieldset> <label for="first_name">First Name:</label> <input type="text" name="first_name" size="20"> <label for="last_name">Last Name:</label> <input type="text" name="last_name" size="20"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> <label for="user_pic"> :</label> <input type="file" name="user_pic" size="30"> <input type="submit" value=""> <input type="reset" value=""> </fieldset> </form>
enctype="multipart/form-data". . 25 , hidden . 2 , .
action <?php echo $_SERVER['PHP_SELF'];?>, , . , , , , create_profile.php. , PHP move uploaded file , .
<?php // $first_name = htmlspecialchars(trim($_REQUEST['first_name'])); $last_name = htmlspecialchars(trim($_REQUEST['last_name'])); // $uploads_dir = HOST_WWW_ROOT."uploads/profile_pics/"; $image_fieldname = "user_pic"; // PHP- $php_errors = array(1 => ' . , php.ini', 2 => ' . , HTML', 3 => ' ', 4 => ' .'); // ($_FILES[$image_fieldname]['error']==0) or die(" ". $php_errors[$_FILES[$image_fieldname]['error']]); // , @is_uploaded_file($_FILES[$image_fieldname]['tmp_name']) or die(' , !'." : "."'{$_FILES[$image_fieldname]['tmp_name']}'"); // @getimagesize($_FILES[$image_fieldname]['tmp_name']) or die("! ". " {$_FILES[$image_fieldname]['tmp_name']}"); // $now = time(); while(file_exists($upload_filename = $uploads_dir.$now.'-'.$_FILES[$image_fieldname]['name'])){ $now++; } ?>
:
- $upload_dir . HOSW_WWW_ROOT .
- $image_fieldname - HTML-.
, move uploaded file , . , PHP- — , .
$php_errors , . [0] $_FILES[$image_fieldname]['error'], 0. PHP $_FILES - , . , $image_fieldname:
// ($_FILES[$image_fieldname]['error']==0) or die(" ". $php_errors[$_FILES[$image_fieldname]['error']]);
move uploaded file PHP
, , ? ? php.ini upload_max_filesize. Denver. php.ini ( php) :
;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads=On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir upload_tmp_dir="***" ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize=5M ; Maximum number of files that can be uploaded via a single request max_file_uploads=50
, , . 2 . , , — . move_uploaded_file, .