我使用jquery.fineuploader-3.7.0和代码点火器框架的服务器端。罚款上传器无法读取与IE7 iframe响应(已解决)
我的js代码:
$('#manual-fine-uploader').fineUploader({
request : { endpoint: 'declaration/uploadfile'},
autoUpload : false,
template : '<div class="qq-uploader span12">' +
' <pre class="qq-upload-drop-area span12"><span>{dragZoneText}</span></pre>' +
' <div class="qq-upload-button " style="width: auto;">{uploadButtonText}</div>' +
' <span class="qq-drop-processing"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></span>' +
' <ul id="qq-upload-list" class="qq-upload-list" style="margin-top:10px; text-align:center;"><li></li></ul>' +
' <ul class="qq-upload-list" style="margin-top: 10px; text-align: center;"></ul>' +
'</div>',
fileTemplate : '<li>' +
' <div class="qq-progress-bar"></div>' +
' <span class="qq-upload-spinner"></span>' +
' <span class="qq-upload-finished"></span>' +
' <span class="qq-upload-file"></span>' +
' <span class="qq-upload-size"></span>' +
' <a class="qq-upload-cancel" href="#">{cancelButtonText}</a>' +
' <a class="qq-upload-retry" href="#">{retryButtonText}</a>' +
' <a class="qq-upload-delete" href="#">{deleteButtonText}</a>' +
' <span class="qq-upload-status-text">{statusText}</span>' +
'</li>',
failedUploadTextDisplay : {
mode : 'custom',
maxChars : 1500,
responseProperty : 'error',
enableTooltip : true
},
text : {
uploadButton : '<color=#2E6E9E><b>Selectionnez le fichier à déposer</b></color>',
failUpload : 'Le chargement a échoué'
} });
$('#triggerUpload').click(function() {
$('#manual-fine-uploader').fineUploader('setParams', {'id_fait':$('#id_fait').attr('value') });
$('#manual-fine-uploader').fineUploader('uploadStoredFiles'); });
我的服务器端的响应是:
>HTTP/1.0 200 OK
>Date: Fri, 26 Jul 2013 08:12:09 GMT
>Server: Apache/2.2.15 (CentOS)
>X-Powered-By: PHP/5.3.3
>Expires: Thu, 19 Nov 1981 08:52:00 GMT
>Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
>Pragma: no-cache
>Connection: close
>Content-Type: text/html; charset=UTF-8
内容:
{"success":true,"file_inner":"<a href='pj\/'116810_116810_cimpa_insertion.xls' target='_blank'>116810_cimpa_insertion.xls<\/a>"}
在FF,铬我有我的网页上的sucess消息(绿色) 但在IE7或IE8下我有一条消息,在我的调试栏控制台中说过:
[FineUploader 3.7.0]尝试解析iframe上载响应时出错([object Error]) [FineUploader 3.7.0]'错误'不是服务器响应中的有效属性。
和网页错误信息(红色)。 但是上传是可以的(该文件在我的服务器上是正确的)
我是一个精通上传器的初学者,你能帮我找到我犯错的地方吗?
代码在服务器端:
/**
* uploadfile
* @access public
* @return string
*/
public function uploadfile() {
$post['id_fait'] = $this->input->post('id_fait');
if (empty($post['id_fait'])) {
$return['error'] = 'ID_FAIT manquant';
return true;
}
else {
$_FILES['qqfile']['name'] = $post['id_fait']."_".$_FILES['qqfile']['name'];
$config['upload_path'] = DOCUMENT_PATH;
$config['max_size'] = UPLOAD_MAX_SIZE;
$config['overwrite'] = FALSE;
$config['allowed_types'] = ALLOWED_EXT;
$config['remove_spaces'] = FALSE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('qqfile')) { $return['error'] = $this->upload->error_msg[0]; }
else {
$data = $this->upload->data();
$post['fichier'] = $data['file_name'];
$insert = $this->db->insert('senla_faits_piece_jointe',$post);
$return['success'] = $insert;
$return['file_inner'] = "<a href='pj/'".$post['id_fait']."_".$data['file_name']."' target='_blank'>".$data['file_name']."</a>";
}
}
echo json_encode($return, JSON_FORCE_OBJECT);
}
UPDATE: 后,我做出改变我的服务器响应:
HTTP/1.0 200 OK
Date: Fri, 26 Jul 2013 20:21:01 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 124
Connection: close
Content-Type: text/html; charset=UTF-8
和内容:
{"success":true,"file_inner":"<a href=\"pj\/116842_116842_brochure 12.pdf\" target=\"_blank\">116842_brochure 12.pdf<\/a>"}
我一直一个红色的Web消息谁说:上传失败(法语),这个消息在我的调试酒吧控制台:
[FineUploader 3.7.0] Error when attempting to parse iframe upload response ([object Error])
[FineUploader 3.7.0] 'error' is not a valid property on the server response.
感谢很多的帮助
斯特凡
更新2变更后的内容类型,总是同样的问题: 服务器响应:
HTTP/1.0 200 OK
Date: Sat, 27 Jul 2013 20:14:38 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=7riosh2q9edldanjp9vtg4ili3; path=/
Set-Cookie: PHPSESSID=7riosh2q9edldanjp9vtg4ili3; path=/
Connection: close
Content-Type: text/plain; charset=UTF-8
内容:
{"success":true,"file_inner":"<a href=\"pj\/116841_116841_capture_portail_sonacotra.doc\" target=\"_blank\">116841_capture_portail_sonacotra.doc<\/a>"}
我认为这不是内容的问题,也许这是谁也无法读取通过在iframe中的服务器发送响应IE的问题,但我不充分了解JavaScript来找到解决方案
更新29/07/2013: 我必须做一个测试: 如果我删除了$返回[“file_inner”] 而我只保留的研制成功或错误信息,那么这是确定
我的$返回[“file_inner” ]就在这里,因为用户可以点击链接验证文档上传。但这不是一个非常重要的功能,我可以删除它。 也许我已经忘记了一些东西,当他们是我的对象“响应”几个属性。或者也许罚款上传者代码只能等待一个属性。
解决:
的解决方案是在为例PHP脚本,我的错误是在做我的物件的网址没有用htmlspecialchars转换。有了这个在服务器端的PHP代码,这是好的 非常感谢您的时间。
/**
* uploadfile
* @access public
* @return string
*/
public function uploadfile() {
$post['id_fait'] = $this->input->post('id_fait');
if (empty($post['id_fait'])) {
$return['error'] = 'ID_FAIT manquant';
return true;
}
else {
$_FILES['qqfile']['name'] = $post['id_fait']."_".$_FILES['qqfile']['name'];
$config['upload_path'] = DOCUMENT_PATH;
$config['max_size'] = UPLOAD_MAX_SIZE;
$config['overwrite'] = FALSE;
$config['allowed_types'] = ALLOWED_EXT;
$config['remove_spaces'] = FALSE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload('qqfile')) { $return['error'] = $this->upload->error_msg[0]; }
else {
$data = $this->upload->data();
$post['fichier'] = $data['file_name'];
$insert = $this->db->insert('senla_faits_piece_jointe',$post);
$return['success'] = $insert;
$return['file_inner'] = "<a href=\"pj/".$post['id_fait']."_".$data['file_name']."\" target=\"_blank\">".$data['file_name']."</a>";
}
}
// log_askel($this->upload);
header('Content-type: text/plain');
echo htmlspecialchars(json_encode($return), ENT_NOQUOTES);
}
非常好的问题。感谢您花时间提供所有这些信息,并且如此清楚地解释您的问题。看到一个格式良好的问题令人耳目一新,我希望更多的人在Stackoverflow上发布与您的问题一样详细和完整的问题。 –
确保您在客户端和服务器上都使用UTF-8。 –
我已经更新了我的答案,请看看。 –