Server-side code uploaded to the server--there is a problem

Source: Internet
Author: User

<form action= "" enctype= "Multipart/form-data" method= "POST" >

Name= "UploadFile" > Upload file: <input type= "file" Name= "Upfile"/><br>

<input type= "Submit" value= "Upload"/>

</form>

<?php

if (Is_uploaded_file ($_files[' upfile ' [' tmp_name ']))

{

$upfile =$_files["Upfile"];

Gets the value inside the array

$name = $upfile ["name"];//the filename of the uploaded file

$type = $upfile ["type"];//upload file type

$size = $upfile ["Size"];//upload files

$tmp _name= $upfile ["Tmp_name"];//the temporary storage path of the uploaded file

Determine if it is a picture

Switch ($type) {

Case ' image/pjpeg ': $okType =type;

Break

Case ' image/jpeg ': $okType =type;

Break

Case ' image/gif ': $okType =type;

Break

Case ' image/png ': $okType =type;

Break

}

if ($okType) {

0: File Upload success </br>

1: File size exceeded, set in php.ini file

2: The value of the file max_file_size option is exceeded

3: Files are only partially uploaded

4: No file Upload

5: Upload file is 0

$error = $upfile ["Error"];//the value returned by the system after uploading

echo "________________<br/>";

echo "Upload file name is:". $name. " <br/> ";

echo "Upload file type is:". $type. " <br/> ";

echo "Upload file size is:". $size. " <br/> "

echo "The value returned by the system after uploading is:". $error. " <br/> ";

echo "The temporary storage path for uploading files is:". $tmp _name. " <br/> ";

echo "Start moving upload file <br/>";

Move the uploaded temporary files to the up directory below

Move_uploaded_file ($tmp _name, ' up/'. $name);

$destination = "up/". $name;

echo "----------------<br/>"

echo "Upload information:<br/>";

if ($error ==0) {

echo "File Upload successful! ";

echo "<br> picture preview:<br>";

echo "img scr=". $destination. " > ";

}elseif ($error ==1) {

echo "Exceeds file size, set in php.ini file";

}elseif ($error ==2) {

echo "exceeds the size of the file max_file_size option specified value";

}elseif ($error ==3) {

echo "file is only partially uploaded";

}elseif ($error ==4) {

echo "No files were uploaded";

}else{

echo "Upload file size is 0";

}

}else{

echo "Please upload pictures in jpg,gif,png and other formats"

}

}

?>

Server-side code uploaded to the server--there is a problem

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.