我有一个在本地安装(PHP4 / MySQL)中设计的应用程序,它运行良好。自从我把它移到实时安装(PHP5 / MySQL)后,我什么都没有问题!我修复了任何全局变量问题(引导我学习PDO所以不是坏事!)而不打开全局变量,所以我唯一的问题是文件上传。我尝试了$ _file的isset测试,看起来变量从未设置过?有任何想法吗?
以下是表单数据:
<form enctype="multipart/form-data" method="post" action="script_add_product.php" >
<input class="cp_forms_upload" type="file" name="full_image" />
<input class="cp_formsButton" type="submit" name="submit_button" value="Add Product" /></form>
这是PHP:
$full_image_url = $_FILES["full_image"]["name"];
if ((($_FILES["full_image"]["type"] == "image/gif")
|| ($_FILES["full_image"]["type"] == "image/jpeg")
|| ($_FILES["full_image"]["type"] == "image/pjpeg")
|| ($_FILES["full_image"]["type"] == "image/png"))
&& ($_FILES["full_image"]["size"] < 400000))
{
if ($_FILES["full_image"]["error"] > 0)
{
echo "Return Code: " . $_FILES["full_image"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["full_image"]["name"] . "<br />";
echo "Type: " . $_FILES["full_image"]["type"] . "<br />";
echo "Size: " . ($_FILES["full_image"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["full_image"]["tmp_name"] . "<br />";
if (file_exists("../Uploads/" . $_FILES["full_image"]["name"]))
{
echo $_FILES["full_image"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["full_image"]["tmp_name"],
"../Uploads/" . $_FILES["full_image"]["name"]);
echo "Stored in: " . "../Uploads/" . $_FILES["full_image"]["name"];
echo "<br /><br /><br />" . $full_image_url;
}
}
}
else
{
echo "Invalid file";
}
谢谢大家:)
答案 0 :(得分:0)
如果php.ini
设置为file_uploads
,您是否可以检查On
。
; Whether to allow HTTP file uploads.
; http://ph .net/file-uplollow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
答案 1 :(得分:0)
请参阅php.ini
config。
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = "...../tmp"
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M
memory_limit
中的max_execution_time
和php.ini
配置参数可能也很有用。
更多:Handling file Uploads -> Common Pitfalls
确保文件夹"../Uploads/"
存在,并且有权在apache / nginx work(www_data
或其他类似工具)下为用户编写
答案 2 :(得分:-1)
这可能是问题吗?另外一个'(本节中的括号:
if (($_FILES["full_image"]["type"] == "image/gif")
|| ($_FILES["full_image"]["type"] == "image/jpeg")
|| ($_FILES["full_image"]["type"] == "image/pjpeg")
|| ($_FILES["full_image"]["type"] == "image/png"))
&& ($_FILES["full_image"]["size"] < 400000))