您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页php如何存储图片

php如何存储图片

来源:爱够旅游网

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>

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务