[英]PHP upload script works locally, however not on remote server
It's strange, this script works locally (on MAMP), but not on my remote server (Bluehost). 奇怪的是,此脚本在本地(在MAMP上)有效,但在我的远程服务器(Bluehost)上不起作用。 I tried adding some POST data, and that worked, however the file upload isn't working at all.
我尝试添加一些POST数据,但效果很好,但是文件上传根本不起作用。 Any ideas?
有任何想法吗?
//upload file
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 2000000) && isSet($_FILES["file"])){
if ($_FILES["file"]["error"] > 0){
echo "<div class='error'>Return Code: " . $_FILES["file"]["error"] . "</div>";
}else{
if (file_exists("../upload/" . $_FILES["file"]["name"])){
echo "<div class='error'>" . $_FILES["file"]["name"] . " already exists. </div>";
}else{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../upload/" . $_FILES["file"]["name"]);
}
}
}else{
if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg"))){
//echo "<div class='error'>Invalid file</div>";
}else{
if(isSet($_FILES["file"]["type"]) && !isSet($message)){
echo "<div class='error'>Invalid file type.</div>";
}
}
}
Here is the upload form. 这是上传表格。
<form action="index.php" method="post" enctype="multipart/form-data">
<div>
<input type="file" name="file" id="file" />
<input type="submit" id="submit" value="Submit" />
</div>
</form>
The upload folder's permissions are set to "775". 上传文件夹的权限设置为“ 775”。
I'd appreciate any help/ideas. 我将不胜感激任何帮助/想法。
Update 更新资料
Problem solved. 问题解决了。 It was a php.ini issue.
这是一个php.ini问题。 I'm not sure where the problem was exactly.
我不确定问题出在哪里。 However, when I restored the default php.ini, file it worked.
但是,当我恢复默认的php.ini时,它起作用了。
I think problems is with the read-write-execute permission of the upoading folder in server. 我认为问题出在服务器中upoading文件夹的读写执行权限上。 Make sure that the destination folder have read-write-execute(777) permissions.
确保目标文件夹具有读写执行(777)权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.