PHP implements the function of uploading pictures

王林
Release: 2023-04-08 08:06:01
forward
6354 people have browsed it

PHP implements the function of uploading pictures

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


Copy after login

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 "无效的文件"; }
Copy after login

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!

Related labels:
source:cnblogs.com
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!