Okay, so this is a tough one, I've spent hours looking for a solution/problem. I'm using SWFUpload to upload images without reloading the page (with a fancy progressbar too), this works fine when I'm on localhost (Wamp server), but it goes nuts when I try to do so on my real linux server (which is the only possible flag as far as I could see), it's running Apache2 and PHP5. As I said the front-end is fine (apart maybe from the fact it's flash). The back-end code is as follows:
好的,所以这是一个艰难的,我花了几个小时寻找解决方案/问题。我正在使用SWFUpload上传图像而不重新加载页面(也有一个花哨的进度条),这在我在localhost(Wamp服务器)时工作正常,但是当我尝试在我真正的Linux服务器上这样做时它很疯狂(这是我能看到的唯一可能的标志),它正在运行Apache2和PHP5。正如我所说,前端很好(除了可能是它的闪光)。后端代码如下:
SWFUpload_settings.js
var swfu_settings ={upload_url : "upload.php",
flash_url : "flash/swfupload.swf",
button_placeholder_id : "upload_flash",
file_size_limit : "2 MB",
file_types : "*.gif;*.jpg;*.png",
file_post_name : "Filedata",
file_queue_limit : 1,
post_params : {
"PHPSESSID" : getCookie()
},
upload_start_handler : upload_start,
upload_error_handler : upload_error,
upload_complete_handler : upload_complete,
upload_progress_handler : upload_progress,
file_queued_handler : file_queued,
button_disabled : false,
button_width : 120,
button_height : 22,
button_text : '<div class="adm_upload">Select image</div>',
button_text_style : '.adm_upload{color:#ff0000;}'
};
upload.php
function manageUpload(){
if( isset($_FILES['Filedata']) ){
$dest_dir = $_SERVER[DOCUMENT_ROOT]."/images/products";
$destination = $_SERVER[DOCUMENT_ROOT]."/images/products/" . $_FILES['Filedata']['name'];
if( is_dir($dest_dir) ){
if( is_writable($dest_dir) ){
if( !move_uploaded_file($_FILES['Filedata']['tmp_name'], $destination ) ){
$html_body = '<h1>File upload error!</h1>';
switch ($_FILES['Filedata']['error']) {
case 1:
$html_body .= 'The file is bigger than this PHP installation allows';
break;
case 2:
$html_body .= 'The file is bigger than this form allows';
break;
case 3:
$html_body .= 'Only part of the file was uploaded';
break;
case 4:
$html_body .= 'No file was uploaded';
break;
default:
$html_body .= 'unknown errror';
}
echo ($html_body);
}
}
else{
echo "Says it's not writable: ".$dest_dir;
}
}
else{//not a directory?
echo "Says it's not a directory:".$dest_dir;
}
}
else{
echo "No file POSTED.\n";
}
}
The only error that I get is from $_FILES['Filedata']['error'] = 3, 'Only part of the file was uploaded'. The destination directory does have 777 permission and you can see I made the required checks. It simply will not work, I have no idea why. Also, the files I tried uploading had no spaces in the filename, so that shouldn't fit under the issue 206 with SWFUpload.
我得到的唯一错误来自$ _FILES ['Filedata'] ['error'] = 3,'只上传了部分文件'。目标目录具有777权限,您可以看到我进行了必要的检查。它根本行不通,我不明白为什么。此外,我尝试上传的文件在文件名中没有空格,因此不适合使用SWFUpload的问题206。
As far as I can tell it can be either due to the front-end SWFUpload or back-end server configuration. Please help.
据我所知,它可能是由于前端SWFUpload或后端服务器配置。请帮忙。
P.S. no need to mention security, this is only allowed to be used by the server admin with external access anyhow, plus there's the front-end limitation on the files he can select (images). There was no point securing it further.
附:不需要提及安全性,只允许服务器管理员使用外部访问,加上他可以选择的文件(图像)的前端限制。没有必要进一步确保它。
2 个解决方案
#1
0
Problem is actually server configuration. Since built-in PHP does not support putting together partial uploads, you must implicitly tell the browser you don't support them!
问题实际上是服务器配置。由于内置PHP不支持将部分上传组合在一起,因此您必须隐式告诉浏览器您不支持它们!
Here are a few options:
以下是一些选项:
- Configure webserver to send the header "Allow-Ranges: none" for all PHP requests.
- Implicitly close the connection after each upload. Add
header('Connection: close');
to the server side script. - Turn KeepAlives off.
配置webserver以为所有PHP请求发送标头“Allow-Ranges:none”。
每次上传后隐式关闭连接。添加标题('连接:关闭');到服务器端脚本。
关闭KeepAlives。
#2
-3
So it turns out the problem was with the SWFUpload itself, it simply failed when used with linux servers. To anyone who has similar problems, consider using this instead:
事实证明问题出在SWFUpload本身,当它与linux服务器一起使用时它就失败了。对于有类似问题的人,请考虑使用此代码:
ridiculously easy to adapt, works out of the box and you can customize it to your hearts content with ease. I implemented all I wanted in under 20 minutes, it's a pure delight to use and works well. Beautifully designed.
非常容易适应,开箱即用,您可以轻松地自定义它的内容。我在20分钟内实现了我想要的所有功能,使用起来非常愉快,效果很好。设计精美。
#1
0
Problem is actually server configuration. Since built-in PHP does not support putting together partial uploads, you must implicitly tell the browser you don't support them!
问题实际上是服务器配置。由于内置PHP不支持将部分上传组合在一起,因此您必须隐式告诉浏览器您不支持它们!
Here are a few options:
以下是一些选项:
- Configure webserver to send the header "Allow-Ranges: none" for all PHP requests.
- Implicitly close the connection after each upload. Add
header('Connection: close');
to the server side script. - Turn KeepAlives off.
配置webserver以为所有PHP请求发送标头“Allow-Ranges:none”。
每次上传后隐式关闭连接。添加标题('连接:关闭');到服务器端脚本。
关闭KeepAlives。
#2
-3
So it turns out the problem was with the SWFUpload itself, it simply failed when used with linux servers. To anyone who has similar problems, consider using this instead:
事实证明问题出在SWFUpload本身,当它与linux服务器一起使用时它就失败了。对于有类似问题的人,请考虑使用此代码:
ridiculously easy to adapt, works out of the box and you can customize it to your hearts content with ease. I implemented all I wanted in under 20 minutes, it's a pure delight to use and works well. Beautifully designed.
非常容易适应,开箱即用,您可以轻松地自定义它的内容。我在20分钟内实现了我想要的所有功能,使用起来非常愉快,效果很好。设计精美。