我有一个功能,可以上传到从某个页面发布的亚马逊s3图像。
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png"))
//&& ($_FILES["upload"]["size"] < 20000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
//uploading here
} else {
echo 'Image not uploaded! :(';
}
}
} else {
echo "Invalid file";
}
工作正常!但现在我在/tmp/
文件夹上的服务器上有一个图像,我需要上传这个,我该怎么办?
谢谢!
答案 0 :(得分:0)
检查move_uploaded_file
功能。并var_dump($_FILES['file']);
查看您对上传文件的信息。
上传$_FILES['file']['tmp_name'];
答案 1 :(得分:0)
$uploads_dir = 'path/to/some/dir';
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
另外,一个好习惯是将$ _FILES [“file”] [“type”]放入变量中,并在if检查中使用该变量,而不是每次都使用$ _FILES数组:
$_type = $_FILES["file"]["type"];
if ((($_type == "image/gif") || ($_type == "image/jpeg") || ($_type == "image/jpg") || ($_type == "image/pjpeg") || ($_type == "image/x-png") || ($_type == "image/png"))
&& in_array($extension, $allowedExts)) {