Home > Article > Backend Development > How to store pictures in php
It is very simple for php as a backend to accept uploaded images. You need to use FILES. When the client or web end posts images to the backend, we can use FILES. ,When the client or web end posts a picture to the backend, we can use _FILE to receive the picture, then store it in a temporary buffer, and finally use the move_upload_file function to save it locally. (Recommended learning: PHP video tutorial)
<?php $imgname = $_FILES['myfile']['name']; $tmp = $_FILES['myfile']['tmp_name']; $filepath = 'photo/'; if(move_uploaded_file($tmp,$filepath.$imgname.".png")){ echo "上传成功"; }else{ echo "上传失败"; } ?>
Code:
/html代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Insert title here</title> </head> <body> <form action="./uploadheadimg.php" method="post" enctype="multipart/form-data"> <!-- <input type="hidden" name="MAX_FILE_SIZE" value='176942' /> --> 请选择您要上传的文件:<input type="file" name='myfile' /> <!-- <input type="file" name="myFile" accept="image/jpeg,image/gif,image/png"/><br /> --> <input type="submit" value="上传文件" /> </form> </body> </html>
The above is the detailed content of How to store pictures in php. For more information, please follow other related articles on the PHP Chinese website!