[英]jQuery File Upload not Uploading
This PHP code works when I use HTML <input type="file">
, but not when I use the jQuery file upload script at the very bottom. 当我使用HTML
<input type="file">
,此PHP代码有效,但在最底部使用jQuery文件上传脚本时,此PHP代码不起作用。
getcwd();
getcwd();
, I believe I'm using correct paths One thing that is also not working, which I'm saying to possibly give a clue, is the upload & cancel buttons next to the file name are not showing all though clicking on them does seem to work. 我要说的一个可能也是不起作用的事情是,尽管单击文件名旁边的文件名旁边的“上载和取消”按钮似乎没有全部显示。
Echo'ing $_POST shows me nothing on submit, but I think that's a javascript thing; 回显$ _POST不会显示任何提交内容,但是我认为这是JavaScript的事情; not sure as I'm a beginner (3-months).
不确定,因为我是初学者(3个月)。
PHP page PHP页面
$filename = $_FILES['userfile']['name'];
$tmpname = $_FILES['userfile']['tmpname'];
$filesize = $_FILES['userfile']['size'];
$filetype = $_FILES['userfile']['type'];
$fp = fopen($tmpname, 'r');
$content = fread($fp, filesize($tmpname));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()) {
$filename = addslashes($filename);
}
$filename = preg_replace('/[ ]/', '~', $filename);
$document_folder = $_SESSION['users_id'];
$destfile = "../_documents/".$document_folder."/".$_FILES['userfile']['name'];
move_uploaded_file( $_FILES['userfile']['tmpname'], $destfile );
HTML page HTML页面
<link type="text/css" rel="Stylesheet" href="../jqx.base.css" />
<script type="text/javascript" src="../scripts/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../scripts/jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../scripts/jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../scripts/jqwidgets/jqxfileupload.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#jqxFileUpload').jqxFileUpload({ width: 300, uploadUrl: 'doc_upload_jquery.php', fileInputName: 'userfile', autoUpload: true });
});
$('#jqxFileUpload').on('uploadStart', function (event) {
var fileName = event.args.file;
$('#log').prepend('Started uploading: <strong>' + fileName + '</strong><br />');
});
$('#jqxFileUpload').on('remove', function (event) {
var fileName = event.args.file;
$('#log').prepend('Removed file: <strong>' + fileName + '</strong><br />');
});
$('#jqxFileUpload').on('uploadEnd', function (event) {
var args = event.args;
var fileName = args.file;
var serverResponce = args.response;
});
</script>
</head>
<body>
<div id="jqxFileUpload">
</div>
<div id="log" style="margin-top: 20px;"></div>
<br />
</body>
</html>
mdpalow - mdpalow-
You probably aren't getting any errors or output because of the if statement at the top: 由于顶部的if语句,您可能没有得到任何错误或输出:
if (isset($_POST['submit']) && $_FILES['userfile']) {
Try putting this at the top to output all of your post variables so that you can determine what post variables are actually being sent (if any): 尝试将其放在顶部以输出所有post变量,以便您可以确定实际发送的post变量(如果有):
print_r($_POST);
I have done file uploads before but not with this specific library - my guess is that its just sending mulipart data instead of POST variables. 我之前已经完成了文件上传,但是没有使用该特定库上传-我的猜测是它只是发送mulipart数据而不是POST变量。 Looking at the preview headers in the browser developer tools will also shed light as to what data is being sent.
在浏览器开发人员工具中查看预览标头也将阐明正在发送的数据。
The problem is that jQuery plugin uploads file via AJAX. 问题是jQuery插件通过AJAX上传文件。 In order to fix the issue please follow next steps:
为了解决此问题,请按照以下步骤操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.