Home > Backend Development > PHP Tutorial > Detailed analysis of php image file upload_PHP tutorial

Detailed analysis of php image file upload_PHP tutorial

WBOY
Release: 2016-07-20 11:09:45
Original
901 people have browsed it

upload_err_ok              no error occurred.

上传成功
 
upload_err_ini_size        the uploaded file exceeds the maximum value specified in the php教程.ini file.
超出最大上传尺寸

upload_err_form_size       the uploaded file exceeds the maximum value specified by the max_file_size hidden widget.
超出form设置最大上传尺寸
 
upload_err_partial         the file upload was canceled and only part of the file was uploaded.
 
upload_err_nofile          no file was uploaded.

未上传文件



a simple file upload form


action="" method="post">









实例一

]
 
 a file upload script
 
 
 


  if ( isset( $_files['fupload'] ) ) {

print "name: ". $_files['fupload']['name'] ."
";
     print "size: ".     $_files['fupload']['size'] ." bytes
";
     print "temp name: ".$_files['fupload']['tmp_name']   ."
";
     print "type: ".     $_files['fupload']['type']       ."
";
     print "error: ".    $_files['fupload']['error']      ."
";

     if ( $_files['fupload']['type'] == "image/gif" ) {

         $source = $_files['fupload']['tmp_name'];
         $target = "upload/".$_files['fupload']['name'];
         move_uploaded_file( $source, $target );// or die ("couldn't copy");
         $size = getimagesize( $target );

         $imgstr = "

$imgstr .= "src="$target" alt="uploaded image" />

";

         print $imgstr;
     }
 }
 ?>
 


 
     action="" method="post">
 


 
 

 
 


 

 
 

文件上传实例二

$maxsize=28480;
if (!$http_post_vars['submit']) {
    $error=" ";
}
if (!is_uploaded_file($http_post_files['upload_file']['tmp_name']) and !isset($error)) {
    $error = "you must upload a file!

";
    unlink($http_post_files['upload_file']['tmp_name']);
}
if ($http_post_files['upload_file']['size'] > $maxsize and !isset($error)) {
    $error = "error, file must be less than $maxsize bytes.

";
    unlink($http_post_files['upload_file']['tmp_name']);
}
if (!isset($error)) {
    move_uploaded_file($http_post_files['upload_file']['tmp_name'],
                       "uploads/".$http_post_files['upload_file']['name']);
    print "thank you for your upload.";
    exit;
}
else
{
    echo ("$error");
}
?>




method="post" enctype="multipart/form-data">
    choose a file to upload:

   
   

   



www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444783.htmlTechArticleupload_err_ok no error occurred. 上传成功 upload_err_ini_size the uploaded file exceeds the maximum value specified in the php教程.ini file. 超出最大上传尺寸 upload_e...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template