Home > Backend Development > PHP Problem > How to set the php image storage path

How to set the php image storage path

藏色散人
Release: 2023-03-10 20:22:01
Original
5114 people have browsed it

How to set the php picture storage path: first set "enctype="multipart/form-data"" in the html form; then get the temporary file name and upload file name through picture; finally store the uploaded file in Just specify the location.

How to set the php image storage path

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to set the php image storage path?

php stores image files to the specified folder

PHP file upload processing 01_$_FILES object

The following settings need to be made in the html code when uploading files:

  • You need to set enctype="multipart/form-data" in the html form
  • Only PHP can receive files in post mode and can obtain them through $_FILES
    First html code
        
Copy after login
                                  

This part of the php code tests the specific content of the $_FILES file

<?php   
  sleep(5);// 让服务器休息一会
  print_r($_FILES);
?>
Copy after login

The running results are as follows

How to set the php image storage path

##Operation description:


    After clicking submit, the server did not respond immediately, but took a rest for a while sleep(5)
  • A .tmp file appeared under the wamp/tmp directory
  • .tmp file will be automatically deleted after a while
  • Among the content returned by the server, there is the name of the file [name] => computer.png, and the location where the uploaded file is saved D:\wamp \tmp\php3D70.tmp
PHP File Upload Processing 02_File Saving

Just demonstrated the role of the $_FILES object, and when PHP accepts the uploaded file, it will first be saved in a Under the temporary directory, then we will demonstrate how to save the files under the temporary directory

The code in the HTML part will not be changed
The following is the printed file related

Array ( [picture] => Array ( 
        [name] => computer.png 
        [type] => image/png 
        [tmp_name] => D:\wamp\tmp\php8913.tmp 
        [error] => 0 [size] => 5212 ) 
    )
Copy after login
The php code is as follows

We need to obtain the temporary file name and upload file name through picture (determined according to the name attribute of the form tag)
<?php   
    sleep(5);// 让服务器休息一会,方便我们查看上传的临时文件
    // 第一个参数是 规定要移动的文件
    // 第二个参数是 规定文件的新位置
    move_uploaded_file($_FILES[&#39;picture&#39;][&#39;tmp_name&#39;], &#39;./upload/&#39;.$_FILES[&#39;picture&#39;][&#39;name&#39;]);
 ?>
Copy after login
rrree
Recommended learning: "

PHP Video Tutorial"

The running results are as follows

How to set the php image storage path

Be sure to ensure that the transfer folder has read and write permissions

The above is the detailed content of How to set the php image storage path. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template