我有一个php脚本,通过FTP发送大文件。发送文件后,我试图向浏览器写入"成功"。我还试图向数据库发送查询,以记录该文件已发送。但是,在ftp_put
之后的任何代码都不会被执行。
if (ftp_put($conn_id, $upload_filename, $filename, FTP_BINARY))
{
echo "File Sent";
echo $upload_filename." - ".date("d/m/Y H:i:s")." - ".filesize($filename)." bytes<br>" ;
}
else
{
echo "Problem while Uploading $filenamen <br/>". $upload_filename ;
}
如果ftp_put
是false
,回声正常。但是,如果ftp_put
成功,我放在那里的任何代码都不会运行。
我发送的文件大小是7305kb
这里的问题很可能是您的脚本在文件上传时超时。尝试在上面的代码之前添加这一行:
set_time_limit(0);
问题是ftp_put()
阻止任何进一步的操作,直到上传完成。试试ftp_nb_put()
(没有阻塞),像这样:
$upload = ftp_nb_put($conn_id, $upload_filename, $filename, FTP_BINARY);
if($upload == FTP_MOREDATA)
{
echo 'Uploading ' . $upload_filename . ' - ' . date("d/m/Y H:i:s") . ' - ' . filesize($filename) . ' bytes<br />';
while($upload == FTP_MOREDATA)
{
echo '.'; //Output a . to page or do whatever
$upload = ftp_nb_continue($conn_id);
}
}
//Note: While in the while above, it will either end in FTP_FINISHED or FTP_FAILED
if($upload == FTP_FAILED)
{
echo "Problem while Uploading $filenamen <br />". $upload_filename;
}