
php作为后端接受上传的图片还是很简单的,需要用到FILES,当客户端或web端向后端post图片时,我们可以用FILES,当客户端或web端向后端post图片时,我们可以用_FILE接收图片,然后存储在临时缓冲区中,最后用move_upload_file函数保存在本地。(推荐学习:PHP视频教程)
<?php
$imgname = $_FILES['myfile']['name'];
$tmp = $_FILES['myfile']['tmp_name'];
$filepath = 'photo/';
if(move_uploaded_file($tmp,$filepath.$imgname.".png")){
echo "上传成功";
}else{
echo "上传失败";
}
?>代码:
/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>
以上就是php如何存储图片的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号