【发布时间】:2016-04-01 00:34:20
【问题描述】:
您好,感谢您抽出宝贵时间。
我正在尝试使用以下代码强制将一个 .png 图像下载到用户计算机上,该图像是从我开发的 Unity 应用程序创建的。
<?php
//get the input information
$stringName = $_POST["stringName"];//name
$imageString = $_POST["imageString"];//image in string form
$dataX = base64_decode($imageString);//make the string into the image
file_put_contents($stringName, $dataX);//save the image on the server
//everything thing above this line works within Unity
$fileSize = filesize($stringName);//get the file size
//bunch of headers, comments next to the ones I have an idea about
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: imagepng");//gives content type
header("Content-Length: ".$fileSize);//file size
header("Content-Disposition: attachment; filename=".$stringName);//download file path
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile( $stringName );
?>
我有这个,但它没有弹出下载确认框,也没有对提供的图像做任何事情。
在浏览器中运行我的程序时,调用上述脚本时出现两个错误之一。由于我从保管箱托管应用程序,我得到“无法从 https 发送到 http”,当我将 php 文件的地址更改为 https 时,它会超时。
首先,有没有办法获得 https 和 http 以允许两者之间的通信,我宁愿不必在 ftp 服务器上托管我的统一项目,因为我有几个项目以相同的方式设置。其次,该 PHP 脚本是否可以正常工作,如果可以,我可以删除一些内容吗?
【问题讨论】:
-
您能否提供有关 http/https 问题的更多信息?
标签: c# php unity3d download ftp