在 xampp 中使用 php 上传文件非常慢
Uploading files using php very slow in xampp
我是新手 developing.I 选择了 php 学习 coding.So 自学过程中可能会出错,请解惑。
我在使用 php 将文件上传到 folder.What 时遇到问题 我确实是这样,我上传了一个文件,该文件保存在一个文件夹中,并且文件名单独插入到数据库中。上传文件时,我确实将文件复制到另一个文件夹,该文件夹将用于编辑目的,这样原始文件就不会 disturbed.Here 我遇到的问题是,文件和名称都已成功上传插入数据库。但是即使文件的大小是 small.It 也需要很长时间才能上传,在我使用本地进行测试时效果很好,但是当我实时进入时,我遇到了这个问题(上传速度慢)。上传负责人所做的是,上传一个文件并打开一个新的浏览器并上传另一个文件。当打开新浏览器时,文件会上传,但在以前的浏览器中它仍在处理中。当打开新浏览器以上传另一组文件时,我编写的用于将文件复制到另一个文件夹的代码未执行。我正在使用 xamp cp v3.2。1.To 最小化执行时间我已将默认最大执行时间设置为 30。但无法快速上传文件。
下面是我的php编码:
<?php
// connect to the database
include('connect-db.php');
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
$file_array=($_FILES['file_array']['name']);
// check to make sure both fields are entered
if ($udate == '' || $file_array=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
// if either field is blank, display the form again
renderForm($udate, $file_array, $error);
}
else
{
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
if(isset($_FILES['file_array']))
{
$name_arrray=$_FILES['file_array']['name'];
$tmp_name_arrray=$_FILES['file_array']['tmp_name'];
for($i=0;$i <count($tmp_name_arrray); $i++)
{
if(move_uploaded_file($tmp_name_arrray[$i],"test_uploads/".str_replace(' ','',$name_arrray[$i])))
{
// save the data to the database
$j=str_replace(' ','',$name_arrray[$i]);
echo $j;
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
$provider = mysql_real_escape_string(htmlspecialchars($_POST['provider']));
$existfile=mysql_query("select ubatch_file from batches");
while($existing = mysql_fetch_array( $existfile)) {
if($j==$existing['ubatch_file'])
echo' <script>
function myFunction() {
alert("file already exists");
}
</script>';
}
mysql_query("INSERT IGNORE batches SET udate='$udate', ubatch_file='$j',provider='$provider',privilege='$_SESSION[PRIVILEGE]'")
or die(mysql_error());
echo $name_arrray[$i]."uploaded completed"."<br>";
$src = 'test_uploads';
$dst = 'copy_test_uploads';
$files = glob("test_uploads/*.*");
foreach($files as $file){
$file_to_go = str_replace($src,$dst,$file);
copy($file, $file_to_go);
/* echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Uploaded.\");
window.location = \"uploadbatches1.php\"
</script>";*/
}
} else
{
echo "move_uploaded_file function failed for".$name_array[$i]."<br>";
}
}
}
// once saved, redirect back to the view page
header("Location:uploadbatches1.php");
}
}
?>
这需要很多时间,因为每次都将所有文件复制到新文件夹中。这超过执行 time.Only 复制上传的文件使得上传和复制文件的速度很快。
我是新手 developing.I 选择了 php 学习 coding.So 自学过程中可能会出错,请解惑。 我在使用 php 将文件上传到 folder.What 时遇到问题 我确实是这样,我上传了一个文件,该文件保存在一个文件夹中,并且文件名单独插入到数据库中。上传文件时,我确实将文件复制到另一个文件夹,该文件夹将用于编辑目的,这样原始文件就不会 disturbed.Here 我遇到的问题是,文件和名称都已成功上传插入数据库。但是即使文件的大小是 small.It 也需要很长时间才能上传,在我使用本地进行测试时效果很好,但是当我实时进入时,我遇到了这个问题(上传速度慢)。上传负责人所做的是,上传一个文件并打开一个新的浏览器并上传另一个文件。当打开新浏览器时,文件会上传,但在以前的浏览器中它仍在处理中。当打开新浏览器以上传另一组文件时,我编写的用于将文件复制到另一个文件夹的代码未执行。我正在使用 xamp cp v3.2。1.To 最小化执行时间我已将默认最大执行时间设置为 30。但无法快速上传文件。
下面是我的php编码:
<?php
// connect to the database
include('connect-db.php');
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
$file_array=($_FILES['file_array']['name']);
// check to make sure both fields are entered
if ($udate == '' || $file_array=='')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
// if either field is blank, display the form again
renderForm($udate, $file_array, $error);
}
else
{
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
if(isset($_FILES['file_array']))
{
$name_arrray=$_FILES['file_array']['name'];
$tmp_name_arrray=$_FILES['file_array']['tmp_name'];
for($i=0;$i <count($tmp_name_arrray); $i++)
{
if(move_uploaded_file($tmp_name_arrray[$i],"test_uploads/".str_replace(' ','',$name_arrray[$i])))
{
// save the data to the database
$j=str_replace(' ','',$name_arrray[$i]);
echo $j;
$udate = mysql_real_escape_string(htmlspecialchars($_POST['udate']));
$provider = mysql_real_escape_string(htmlspecialchars($_POST['provider']));
$existfile=mysql_query("select ubatch_file from batches");
while($existing = mysql_fetch_array( $existfile)) {
if($j==$existing['ubatch_file'])
echo' <script>
function myFunction() {
alert("file already exists");
}
</script>';
}
mysql_query("INSERT IGNORE batches SET udate='$udate', ubatch_file='$j',provider='$provider',privilege='$_SESSION[PRIVILEGE]'")
or die(mysql_error());
echo $name_arrray[$i]."uploaded completed"."<br>";
$src = 'test_uploads';
$dst = 'copy_test_uploads';
$files = glob("test_uploads/*.*");
foreach($files as $file){
$file_to_go = str_replace($src,$dst,$file);
copy($file, $file_to_go);
/* echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Uploaded.\");
window.location = \"uploadbatches1.php\"
</script>";*/
}
} else
{
echo "move_uploaded_file function failed for".$name_array[$i]."<br>";
}
}
}
// once saved, redirect back to the view page
header("Location:uploadbatches1.php");
}
}
?>
这需要很多时间,因为每次都将所有文件复制到新文件夹中。这超过执行 time.Only 复制上传的文件使得上传和复制文件的速度很快。