我使用fopen,fwrite和fclose来重写文件。当我重写一个50mb的大文件时,文件重写成功,但是fclose之后的sql语句没有执行,底部的echo也没有。 sql确实执行20mb的文件
有什么想法吗?
set_time_limit(10000);
if (!file_exists($filename)) {
echo "file missing";
}
else{
$fr = fopen($filename, "r");
$file = "";
$file = fgets($fr, 4096);
while(!feof($fr)){
//read from file
$file =str_replace("\r","",$file);
$file =str_replace("\n","",$file);
$file =str_replace("~","",$file);
//write to file
$fw = fopen($tempfile, "a") or die("Couldn't create new file");
fwrite($fw, $file);
$file = fgets($fr, 4096);
}
fclose($fw);
fclose($fr);
//set status to 5
$update_stmt = $mysqli->prepare("Update bs_uploads set UploadStatus=5 where
UploadNewFilename=?");
$update_stmt->bind_param("s", $original_filename);
$update_stmt->execute();
echo "finished";
}
答案 0 :(得分:0)
导致问题的一件事是你为你阅读的每一块文件打开输出文件......
$fr = fopen($filename, "r");
$fw = fopen($tempfile, "w") or die("Couldn't create new file");
$file = "";
$file = fgets($fr, 4096);
while(!feof($fr)){
//read from file
$file =str_replace("\r","",$file);
$file =str_replace("\n","",$file);
$file =str_replace("~","",$file);
//write to file
//$fw = fopen($tempfile, "a") or die("Couldn't create new file");
fwrite($fw, $file);
$file = fgets($fr, 4096);
}
fclose($fw);
fclose($fr);
不确定是否会导致问题,但打开一堆文件会导致问题。
答案 1 :(得分:0)
当脚本运行很长时间时,似乎松开了mysqli连接。 我通过将我在页面顶部的连接语句移动到我的sql update语句之上来解决这个问题。
Type