qq.FileUploader does not pass any $_FILES data
I'm us开发者_运维问答ing the fileUploader jQuery plugin, I'm testing it out by echoing the $_FILES var, but this always returns empty and I get a Failed response for the fileUploader. Any ideas why it's not submitting the image data?
Thank you!
Most of the server blocks Third party srcipts like http://valums.com/ajax-upload/ ..for bypassing this you need to add these lines to your .htacess file
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
qqFileUPload tries to send the file data using a bytestream, not the normal POST. PHP only puts files that have been POSTed into the $_FILES array.
Luckily, qqFileUploader comes with a class that grabs the special upload and saves it to a file for you: https://github.com/valums/file-uploader/blob/master/server/php.php
Good luck!
PS. I was using this uploader with Symfony, which expects a FILE array in the format PHP noramlly provides in the $_FILES array. So I had to save the file to disk, and create a fake array entry that symfony's forms would accept. This was done using the code below (and the classes I linked to above):
if ($filename = $request->getParameter('qqfile', false)) {
// XMLHttpRequest stream'd upload
$xhrUpload = new qqUploadedFileXhr();
$tmp_name = 'tmp_creative_'.microtime(true);
$tmp_file = sfConfig::get('sf_upload_dir').'/'.$tmp_name;
$xhrUpload->save($tmp_file);
list($width, $height, $type) = getimagesize($tmp_file);
$file = array(
'type' => $type,
'size' => $xhrUpload->getSize(),
'name' => $filename,
'tmp_name' => $tmp_file
);
} elseif (count($_FILES)) {
// Normal file upload
$file = array_shift($_FILES);
} else {
throw new Exception("Did not receive uploaded file.");
}
$form->bind(array(), $file);
if($filename)
{
// If we saved the file manually, php won't consider it a tmp
// file and we need to delete it ourselves.
unlink($tmp_file);
}
精彩评论