图像无法使用move_uploaded_file(PHP)移动到临时文件 [英] Image unable to move to temporary files using move_uploaded_file (PHP)
本文介绍了图像无法使用move_uploaded_file(PHP)移动到临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图像存储到数据库,该数据库首先将图像移动到临时文件,然后只将图像名称保存到mysql数据库。我可以上传图片,但有些图片大小为> 2MB 无法移动到临时文件。我不确定是不是因为授予文件权限因为我看到互联网上的一些论坛在其他人将文件移动到tmp文件时出现问题。
我尝试了什么:
这是我目前使用的编码。
I am trying to store images to database which is moving the image to temporary file first then only save the image name to mysql database. I am able to upload image but some of image which size is > 2MB unable to move to temporary files. I am not sure either it is because of granting permissions to the files since I saw some forum in the internet bring up this matter when others having a problem moving files to tmp file.
What I have tried:
Here is coding that I currently use.
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];
$upload_dir = 'user_images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
// rename uploading image
$userpic = rand(1000,1000000).".".$imgExt;
// allow valid image file formats
if(in_array($imgExt, $valid_extensions)){
// Check file size '5MB'
if($imgSize < 5000000) {
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
$errMSG = "Sorry, your file is too large.";
}
}
else{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
推荐答案
imgFile =
imgFile =
_FILES [' user_image'] [' 名称跨度>];
_FILES['user_image']['name'];
tmp_dir =
tmp_dir =
这篇关于图像无法使用move_uploaded_file(PHP)移动到临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文