【问题标题】:Php Image save as dialog boxphp 图片另存为对话框
【发布时间】:2012-01-11 05:35:41
【问题描述】:

我想在单击图像时打开保存图像对话框。我设法打开了相同的文件,但是保存时,它不会保存打开的保存图像,因为图像的内容没有以某种方式保存。

PHP 代码:

$imageName = $_GET['i'];
$imageName = $imageName . '-HR.jpg';
header ("Content-Type: application/download");
header ("Content-Disposition: attachment; filename=$imageName");
header("Content-Length: " . filesize("$imageName"));
$fp = fopen("$imageName", "r");
fpassthru($fp);

传递的 URL 类似于: mydomain/download_image.php?c=atherothrombosis&i=embolus-carotid-artery-illustration

请提出解决方案。谢谢。

【问题讨论】:

  • 有什么保存吗?即使它不是有效的图像?如果是这样,那是什么!

标签: php image http-headers


【解决方案1】:

也添加这个标题

header("Content-Type: application/force-download");

【讨论】:

    【解决方案2】:

    我通过使用以下代码设法做到了:

    <?php 
    $imageName = $_GET['i'];$imageName = $imageName . '-HR.jpg';
    $imageCatName = $_GET['c'];
    $imageCatName  = ucwords($imageCatName);
    $file_path = $docRoot . '/static/media/images/content/image_library/'.$imageCatName . '/'. $imageName;
    if(file_exists($file_path)) {
    header("Content-disposition: attachment; filename={$imageName}");
    header('Content-type: application/octet-stream'); 
    readfile($file_path); 
    }else {
    echo "Sorry, the file does not exist!";
    }
    ?>
    

    仍然非常感谢您的支持。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多