Home>Article>Backend Development> PHP implements the function of uploading pictures

PHP implements the function of uploading pictures

王林
王林 forward
2020-01-10 17:44:50 6459browse

PHP implements the function of uploading pictures

First you need a form, click the submit button to submit to the upload_file.php file


The upload_file.php file is as follows:

(recommended video tutorial :php video tutorial)

 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "无效的文件"; }

The first step: Determine whether the image format is correct and whether the size is less than 2M, otherwise, "invalid file" will be output;

Second Step: Determine whether an error occurs. If there is an error, enter the error. If no error occurs, perform the next step;

Step 3: Output the image content and determine whether the image exists. If it exists, it will prompt, otherwise it will not. If it exists, perform the operation to save the image to the specified directory: upload.

Recommended related articles and tutorials:php tutorial

The above is the detailed content of PHP implements the function of uploading pictures. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete