About PHP Uploading files

Source: Internet
Author: User
Tags what php

I've never figured out how PHP is going to be uploaded.

It suddenly dawned on me today.

It is not PHP operation upload, after the form submitted file, the file has been placed in the server buffer

What PHP needs to do is before the temporary file disappears at the end of this session. Dump it in one place

The operation is as follows

<?PHPHeader("content-type:text/html; Charset=utf-8 ");$time= Time();if((($_files["File"] ["type"] = = "Image/gif")        || ($_files["File"] ["type"] = = "Image/jpeg")        || ($_files["File"] ["type"] = = "Image/pjpeg"))    && ($_files["File"] ["Size"] < 20000000)){    if($_files["File"] ["error"] > 0)    {        Echo"Return Code:".$_files["File"] ["Error"]. "<br/>"; }    Else    {//echo "Upload:". $_files["File" ["Name"]. "<br/>";//echo "Type:". $_files["File" ["type"]. "<br/>";//echo "Size:". ($_files["File" ["Size"]/1024). "Kb<br/>";//echo "Temp file:". $_files["File" ["Tmp_name"]. "<br/>";        Move_uploaded_file($_files["File"] ["Tmp_name"], "upload/".$time.$_files["File"] ["Name"]);//echo "Stored in:". " Upload/". Time (). $_files["File" ["name"];    }}Else{    Echo"Invalid file";}

$_files Global Variables:

(the first parameter of the $_files is myfile the name value of the submitted form)

$_files[' myFile ' [' Name '] The original name of the client file

The MIME type of the $_files[' myFile ' [' type '] file requires the browser to provide support for that information, such as "Image/gif"

$_files[' myFile ' [' size '] the size of the uploaded file, in bytes

$_files[' myFile ' [' tmp_name '] files are uploaded on the server after the temporary file name stored in the system is generally the default, can be specified in PHP.ini Upload_tmp_dir, but with the putenv () function setting is not working

$_files[' myFile ' [' Error '] and the file upload related error code, [' Error '] is added in PHP 4.2.0, here is its description: (they became constant after PHP3.0)

UPLOAD_ERR_OK value: 0; No error occurred, file upload succeeded

Upload_err_ini_size value: 1; The uploaded file exceeds the value of the Upload_max_filesize option limit in php.ini

Upload_err_form_size value: 2; the size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form

Upload_err_partial value: 3; Files are only partially uploaded

Upload_err_no_file value: 4; No file is uploaded, value: 5; Upload file size of 0

<?php
require_once(__dir__. "/faceppclientdemo.php");

Header("content-type:text/html; Charset=utf-8 ");

$time= Time();

if((($_files["File"]["Type"] == "Image/gif")
|| ($_files["File"]["Type"] == "Image/jpeg")
|| ($_files["File"]["Type"] == "Image/pjpeg"))
&& ($_files["File"]["Size"] <20000000))
{
if($_files["File"]["Error"] >0)
{
Echo"Return Code:". $_files["File"]["Error"] . "<br/>";
}
Else
{
//echo "Upload:". $_files["File" ["Name"]. "<br/>";
echo "Type:". $_files["File" ["type"]. "<br/>";
//echo "Size:". ($_files["File" ["Size"]/1024). "Kb<br/>";
//echo "Temp file:". $_files["File" ["Tmp_name"]. "<br/>";

Move_uploaded_file($_files["File"]["Tmp_name"],
"upload/".$time.$_files["File"]["Name"]);
//echo "Stored in:". " Upload/". Time (). $_files["File" ["Name"];

}
}
Else
{
Echo"Invalid file";
}

About PHP Uploading files

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.