• Flash ProgressEvent.bytesTotal为0的原因和解决


    在“用户访问路径图”的项目中,需要从服务器远程加载用户访问的数据生成地图。为了告诉用户当前加载的进度,需要显示进度条。

     
    然而实际上进度条无法正常显示,经过检查,发现ProgressEvent.bytesTotal始终为零,搜索了一下,没找到理想答案。最后在开发者群里求得了答案:(原文
     
    正常情况下载时可以获取文件大小,flash也是凭借这个来填充ProgressEvent.bytesTotal属性的。但是在下载php生成的动态内容的时候,生成的内容体积无法明确,所以下载时也就无法获得bytesTotal的大小了。(以上内容属猜测)
     
    文中告诉我们,对于PHP程序,可以使用ob_start(); ob_get_length(); ob_end_flush();的方法来解决这一问题。示例代码如下:
    // Turn on output buffering
    ob_start();
    // Get the required image from GET
    $image = $_GET['file'];
    $size = getimagesize($image);
    // create an empty image and copy the original
    $dst_img = imagecreatetruecolor($size[0]/4, $size[1]/4);
    $src_img = imagecreatefromjpeg($image);
    // resize image
    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $size[0]/4, $size[1]/4, $size[0], $size[1]);
    // start output content
    header("Content-type: image/jpeg");
    // display the image
    imagejpeg($dst_img, "", 80);
    // send the content lenght to output
    header("Content-Length: ". ob_get_length());
    // flush the output
    ob_end_flush();
    ?>
  • 相关阅读:
    第七周作业
    第六周作业
    第五周作业
    第四周作业
    第三周作业
    第二周作业
    第一周作业
    老鼠与盈利
    币值转换
    2015 USP-ICMC gym 100733 J. Summer Wars
  • 原文地址:https://www.cnblogs.com/keng333/p/2699948.html
Copyright © 2020-2023  润新知