Home  >  Article  >  Backend Development  >  How to store pictures in php

How to store pictures in php

(*-*)浩
(*-*)浩Original
2019-09-30 15:11:437127browse

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[&#39;myfile&#39;][&#39;name&#39;];
    $tmp = $_FILES[&#39;myfile&#39;][&#39;tmp_name&#39;];
    $filepath = &#39;photo/&#39;;
    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=&#39;176942&#39; /> -->
请选择您要上传的文件:<input type="file" name=&#39;myfile&#39; />
<!-- <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!

Statement:
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