我目前正在使用以下代码上传文件。但我想暂时上传文件,然后想提交表格。我的意思是在选择audiofile>>之后点击文件上传字段旁边的上传按钮。>>消息=文件已成功上传>>然后点击“提交”按钮将相关文件夹中的所有数据和临时上传的文件上传到mysql和音频文件中.... 目前,使用此代码我无法上传更大的文件。经过漫长的等待,我收到错误消息,如“网页不可用” 我为max_execution_time,upload_max_filesize等尝试了php.ini和.htaccess文件更新...还在服务器上禁用了mod_security ...
PHP代码:
<?php
session_start();
// Database connection
include("../include/function.php");
include("commonfiles/validate.php");
// Create an object for an class
$bsq=new bsq();
//use class function to connect the database
$bsq->connect_db();
//
$fileName = $_FILES["audio"]["name"];
$fileNameNew = preg_replace('/\s+/', '_', $fileName);
$fileTmpLoc = $_FILES["audio"]["tmp_name"];
// Path and file name
$pathAndName = "uploadsaudio_admin/".$fileNameNew;
// Run the move_uploaded_file() function here
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
// Evaluate the value returned from the function if needed
$fileName1 = $_FILES["doc"]["name"];
$fileNameNew1 = preg_replace('/\s+/', '_', $fileName1);
$fileTmpLoc1 = $_FILES["doc"]["tmp_name"];
// Path and file name
$pathAndName1 = "uploadsaudiodoc_admin/".$fileNameNew1;
// Run the move_uploaded_file() function here
$moveResult1 = move_uploaded_file($fileTmpLoc1, $pathAndName1);
// Evaluate the value returned from the function if needed
$fileName2 = $_FILES["pdf"]["name"];
$fileNameNew2 = preg_replace('/\s+/', '_', $fileName2);
$fileTmpLoc2 = $_FILES["pdf"]["tmp_name"];
// Path and file name
$pathAndName2 = "uploadsaudioppt_admin/".$fileNameNew2;
// Run the move_uploaded_file() function here
$moveResult2 = move_uploaded_file($fileTmpLoc2, $pathAndName2);
// Evaluate the value returned from the function if needed
if($_POST['action']=="add"){
$all_columns[]="file_subject";
$all_columns[]="full_name";
$all_columns[]="upload_date";
$all_columns[]="display_date";
$all_columns[]="message";
$all_columns[]="audio";
$all_columns[]="doc";
$all_columns[]="pdf";
$display=date('Y-m-d', strtotime("+1 Day"));
//Get All values to insert in to table
$all_values[]=addslashes($_POST["file_subject"]);
$all_values[]=addslashes($_POST["full_name"]);
$all_values[]=addslashes($_POST["upload_date"]);
$all_values[]=$display;
$all_values[]=addslashes($_POST["message"]);
$all_values[]=addslashes($pathAndName );
$all_values[]=addslashes($pathAndName1 );
$all_values[]=addslashes($pathAndName2 );
//=====================
$qry=$bsq->webdreaminsert("eo_uploadsaudio_by_admin",$all_columns,$all_values,'');
echo mysql_error();
header("location:upload_audiofile_for_downloading_list.php");
}
?>
HTML表单代码:
<form action="" method="post" enctype="multipart/form-data" name="addtwebinar1" id="addtwebinar1" onsubmit="javascript:return validateimage1();" >
<input type="hidden" value="add" name="action" />
1) Audio File Subject* : <input name="file_subject" id="file_subject" type="text" value="" />
2) File Owner Name : <input name="full_name" id="full_name" type="text" value="" />
3) Session Conducted On : <input type="text" autocomplete="off" name="upload_date" id="upload_date" placeholder="Click To Open calendar" readonly="readonly" />
4) Your Audio File For Upload : <label for="audio">Audio File To Upload: </label><br>
<input type="file" name="audio" id="audio" />
// Here I want temporary upload button with message "Upload successfully / Not Uploaded..." etc.....
5) Your Doc File For Upload : <label for="doc">Doc File To Upload: </label><br>
<input type="file" name="doc" id="doc" />
6) Your Question Answer File For Upload : <label for="pdf">Question Answer For Practice File To Upload: </label><br>
<input type="file" name="pdf" id="pdf" />
7) Message If Any : <textarea name="message" id="message" cols="" rows="3" placeholder="Message"></textarea>
<button>SUBMIT</button>
</form>
我想在字段编号4旁边添加上传按钮,暂时上传音频文件,然后在填写其他字段后,表格将被提交....
或上传较大文件(每个大小约40到50 MB)的任何其他解决方案,没有任何网络速度较慢的错误?
已编辑问题: 我使用ajax进行文件上传.....现在文件上传到文件夹甚至26 MB但是mysql数据库没有得到更新.....
我已使用javascript编辑HTML代码:
1) Audio File Subject* : <input name="file_subject" id="file_subject" type="text" value="" />
2) File Owner Name : <input name="full_name" id="full_name" type="text" value="" />
3) Session Conducted On : <input type="text" autocomplete="off" name="upload_date" id="upload_date" placeholder="Click To Open calendar" readonly="readonly" />
4) Your Audio File For Upload : <label for="audio">Audio File To Upload: </label><br>
<input type="file" name="audio" id="audio" />
// Here I want temporary upload button with message "Upload successfully / Not Uploaded..." etc.....
5) Your Doc File For Upload : <label for="doc">Doc File To Upload: </label><br>
<input type="file" name="doc" id="doc" />
6) Your Question Answer File For Upload : <label for="pdf">Question Answer For Practice File To Upload: </label><br>
<input type="file" name="pdf" id="pdf" />
7) Message If Any : <textarea name="message" id="message" cols="" rows="3" placeholder="Message"></textarea>
<button>SUBMIT</button>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"> </script>
<script src="source/jquery.form.js"></script>
<script>
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%' + '' + 'Completed...';
bar.width(percentVal)
percent.html(percentVal);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
window.location.href='upload_audiofile_for_downloading_list.php';
}
});
})();
</script>
upload_audiofile_process.php
中的代码:
<?php
session_start();
include("../include/function.php");
include("commonfiles/validate.php");
include("fckeditor.php");
//=================================================================================
// Create an object for an class
$bsq=new bsq();
//use class function to connect the database
$bsq->connect_db();
$fileName = $_FILES["image"]["name"];
$fileNameNew = preg_replace('/\s+/', '_', $fileName);
$fileTmpLoc = $_FILES["image"]["tmp_name"];
// Path and file name
$pathAndName = "uploadsaudio_admin/".$fileNameNew;
// Evaluate the value returned from the function if needed
$fileName1 = $_FILES["doc"]["name"];
$fileNameNew1 = preg_replace('/\s+/', '_', $fileName1);
$fileTmpLoc1 = $_FILES["doc"]["tmp_name"];
// Path and file name
$pathAndName1 = "uploadsaudiodoc_admin/".$fileNameNew1;
// Evaluate the value returned from the function if needed
$fileName2 = $_FILES["pdf"]["name"];
$fileNameNew2 = preg_replace('/\s+/', '_', $fileName2);
$fileTmpLoc2 = $_FILES["pdf"]["tmp_name"];
// Path and file name
$pathAndName2 = "uploadsaudioppt_admin/".$fileNameNew2;
// Evaluate the value returned from the function if needed
if (isset($_FILES["image"])) {
if ($_FILES["image"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
move_uploaded_file($fileTmpLoc, $pathAndName);
move_uploaded_file($fileTmpLoc1, $pathAndName1);
move_uploaded_file($fileTmpLoc2, $pathAndName2);
$all_columns[]="file_subject";
$all_columns[]="full_name";
$all_columns[]="upload_date";
$all_columns[]="display_date";
$all_columns[]="message";
$all_columns[]="image";
$all_columns[]="doc";
$all_columns[]="pdf";
$display=date('Y-m-d', strtotime("+1 Day"));
//Get All values to insert in to table
$all_values[]=addslashes($_POST["file_subject"]);
$all_values[]=addslashes($_POST["full_name"]);
$all_values[]=addslashes($_POST["upload_date"]);
$all_values[]=$display;
$all_values[]=addslashes($_POST["message"]);
$all_values[]=addslashes($pathAndName );
$all_values[]=addslashes($pathAndName1 );
$all_values[]=addslashes($pathAndName2 );
//=====================
$qry=$bsq->webdreaminsert("eo_uploadsaudio_by_admin",$all_columns,$all_values,'');
echo mysql_error();
}
}
?>
此代码适用于10-15 MB文件上传....但如果文件大于20 MB ...不工作....
答案 0 :(得分:0)
您可以通过这种方式解决问题。
首先在上传按钮上调用ajax函数。
$.ajax({
url: 'example.php',
type: 'POST',
data: fileData,
success: function(data) {
// set file name or file id in some field using jquery.
$('#fileHiddenFieldId').val(data);
// and then set css property 'display:block' for submit button.
$('#submitButtonId').css('display','block');
}
});
这里url example.php是你放置php文件上传代码的文件路径。 'fileData'是您发布的上传文件数据。
当您获得成功响应时,请在某个隐藏字段中设置文件ID或文件名,然后显示提交按钮。