Php image file upload detailed analysis

Source: Internet
Author: User
Tags file upload file upload script php print php tutorial

Upload_err_ OK no error occurred.

Uploaded
 
Upload_err_ini_size the uploaded file exceeds the maximum value specified in the php Tutorial. ini file.
Maximum upload size exceeded

Upload_err_form_size the uploaded file exceeds the maximum value specified by the max_file_size hidden widget.
The maximum size of the form file is exceeded.
 
Upload_err_partial the file upload was canceled and only part of the file was uploaded.
 
Upload_err_nofile no file was uploaded.

File Not uploaded

<Html>
<Head>
<Title> a simple file upload form </title>
</Head>
<Body>
<Form enctype = "multipart/form-data"
Action = "<? Print $ _ server ['php _ self ']?> "Method =" post ">
<P>
<Input type = "hidden" name = "max_file_size" value = "102400"/>
<Input type = "file" name = "fupload"/> <br/>
<Input type = "submit" value = "upload! "/>
</P>
</Form>
</Body>
</Html>

Instance 1

] <Html>
<Head>
<Title> a file upload script </title>
</Head>
<Body>
<Div>
<? Php
If (isset ($ _ files ['fupload']) {

Print "name:". $ _ files ['fupload'] ['name']. "<br/> ";
Print "size:". $ _ files ['fupload'] ['size']. "bytes <br/> ";
Print "temp name:". $ _ files ['fupload'] ['tmp _ name']. "<br/> ";
Print "type:". $ _ files ['fupload'] ['type']. "<br/> ";
Print "error:". $ _ files ['fupload'] ['error']. "<br/> ";

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 = "<p> $ Imgstr. = "src =" $ target "alt =" uploaded image "/> </p> ";

Print $ imgstr;
     }
 }
?>
</Div>
<Form enctype = "multipart/form-data"
Action = "<? Php print $ _ server ['php _ self ']?> "Method =" post ">
<P>
<Input type = "hidden" name = "max_file_size" value = "102400"/>
<Input type = "file" name = "fupload"/> <br/>
<Input type = "submit" value = "upload! "/>
</P>
</Form>
</Body>
</Html>

File upload instance 2

<? Php
$ Maxsize = 28480;
If (! $ Http_post_vars ['submit ']) {
$ Error = "";
}
If (! Is_uploaded_file ($ http_post_files ['upload _ file'] ['tmp _ name']) and! Isset ($ error )){
$ Error = "<B> you must upload a file! </B> <br/> ";
Unlink ($ http_post_files ['upload _ file'] ['tmp _ name']);
}
If ($ http_post_files ['upload _ file'] ['size']> $ maxsize and! Isset ($ error )){
$ Error = "<B> error, file must be less than $ maxsize bytes. </B> <br/> ";
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 ");
}
?>

<Html>
<Head> <Body>
<Form action = "<? Php echo (htmlspecialchars ($ _ server ['php _ self '])?> "
Method = "post" enctype = "multipart/form-data">
Choose a file to upload: <br/>
<Input type = "file" name = "upload_file" size = "80">
<Br/>
<Input type = "submit" name = "submit" value = "submit">
</Form>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.