我在这里有一个应用程序,用户在其中添加了一个表格行,它将在该行中显示一个文件输入。现在我遇到的问题是,如果您使用输入选择一个文件并单击“上传”,它总是指出上传文件时出错,任何文件都会发生这种情况。
我已将文件的权限设置为能够读取和写入,但它仍然指出上传文件时出现错误。如果有人使用过 MAx 的 AJAX 文件上传器并且之前遇到过这个问题但后来修复了它,那么我可以问你是如何解决这个问题的。如果没有,那么我是否有其他方法可以解决此问题,以便它停止显示完全合法文件上传的错误消息,而是显示文件上传成功消息。
当我在此链接中测试使用不同服务器的相同代码时:[ er5325.aisites.com/scripts/stack/test.html,然后在上传合法文件时它不会显示错误消息。
我正在使用大学的服务器 helios.hud.ac.uk
下面是文件输入的代码和停止和开始上传的函数:
<script type="text/javascript">
var sourceForm;
function insertQuestion(form) {
var $tbody = $('#qandatbl > tbody');
var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
var $image = $("<td class='image'></td>");
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='startUpload(this);' class='imageuploadform' >" +
"<p class='imagef1_upload_process' align='center'>Loading...<br/><img src='Images/loader.gif' /><br/></p><p class='imagef1_upload_form' align='center'><br/><label>" +
"File: <input name='fileImage' type='file' class='fileImage' /></label><br/><label>" +
"(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label>" +
"<input type='submit' name='submitBtn' class='sbtn' value='Upload' /></label>" +
"</p> <iframe class='upload_target' name='upload_target' src='#' style='wclassth:0;height:0;border:0px;solclass #fff;'></iframe></form>");
$image.append($fileImage);
$tr.append($image);
$tbody.append($tr);
}
function startUpload(imageuploadform){
$(imageuploadform).find('.imagef1_upload_process').css('visibility','visible');
$(imageuploadform).find('.imagef1_upload_form').css('visibility','hidden');
sourceForm = imageuploadform;
return true;
}
function stopUpload(success){
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!<\/span><br/><br/>';
}
else {
result = '<span class="emsg">There was an error during file upload!<\/span><br/><br/>';
}
$(sourceForm).find('.imagef1_upload_process').css('visibility','hidden');
$(sourceForm).find('.imagef1_upload_form').html(result + '<label>File: <input name="fileImage" type="file"/><\/label><br/><label>(jpg, jpeg, pjpeg, gif, png, tif)</label><br/><br/><label><input type="submit" name="submitBtn" class="sbtn" value="Upload" /><\/label>');
$(sourceForm).find('.imagef1_upload_form').css('visibility','visible');
return true;
}
</script>
下面是上传文件的上传页面 (imageupload.php):
<?php
// Edit upload location here
$destination_path = getcwd().DIRECTORY_SEPARATOR;
$result = 0;
$target_path = $destination_path . basename( $_FILES['fileImage']['name']);
if(@move_uploaded_file($_FILES['fileImage']['tmp_name'], $target_path)) {
$result = 1;
}
sleep(1);
?>
<script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>