见下文编辑的问题
我目前正在上传以下代码的文件。但是我想暂时上传文件,然后提交表单。我的意思是在选择了音频>>后,点击上传按钮旁边的文件上传field..>> Message=文件上传成功的>>,然后点击“提交”按钮上传所有数据和临时上传的文件在mysql和音频文件在相关的文件夹.目前,使用此代码,我无法上传更大的文件。经过长时间的等待,我得到了错误消息,比如“网页不可用”,我尝试了php.ini和.htaccess文件更新为max_execution_time,upload_max_filesize等.同时,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...NOT工作.
发布于 2015-09-09 06:04:53
你可以用这种方法解决你的问题。
首先在上传按钮上调用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或文件名,然后显示提交按钮。
https://stackoverflow.com/questions/32471786
复制相似问题