javascript - How to deal with the disconnection of PHP packaged images?
巴扎黑
巴扎黑 2017-06-21 10:11:10
0
1
711

Now there is a need to pack pictures into zip compressed packages. Click the 'Package' button to execute ajax. I am using the ZipArchive class that comes with PHP. The problem now is that if there are 10 pictures, I will pack them halfway. , the computer is disconnected from the Internet, how to remind the user at this time? (Note: Click the 'Package' button, and there will be a loading box. If the network is disconnected midway, this box will not disappear. It will keep loading. After the network is disconnected, the ajax return result will not be sent to the server)

code show as below:

$filename = $path . $orderNumber . ".zip"; // 最终生成的文件名(含路径)
// 生成文件
$zip = new ZipArchive ();
if ($zip->open ( $filename, ZIPARCHIVE::CREATE ) !== TRUE) {
    echo json_encode(array('state'=>0,'msg'=>NoFindFile));
    exit;
}

//$imgArr 就是一个存储文件路径的数组 比如 array('/a/1.jpg,/a/2.jpg....');
foreach ( $imgArr as $val ) {
   $zip->addFile ( $val, basename ( $val ) ); //把图片放入zip里面  成功返回true
}
$zip->close (); // 关闭

之前在foreach里判断是否断网的情况,但是加载框还是不会消失,是不是断网之后,ajax返回结果不会给服务器了?该如何解决最好??谢谢各位
巴扎黑
巴扎黑

reply all(1)
伊谢尔伦

You need to understand the principle of ajax. When the connection between the client and the server is successful, the client is in a waiting state. If, as you said, the server suddenly loses power during the packaging process (why the hell would the server be so black), that is, the server does not send a response, then ajax will have a timeout response time, and you can error to prompt the user that there is a server problem.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template