douzuizhuo0587 2019-02-26 18:48 采纳率: 0%
浏览 101
已采纳

在通过php下载之前添加注释到生成的zip文件

I hope you can help me on this matter. I tested a very simple script to add a comment to a zip file before downloading it, and it worked fine, so now I decided to try implementing it into a file hosting script, but I'm being unable to find a way to edit the generated file.

At line 59 of this file: https://pastebin.com/i3iBmW8s (which is the file which generates the download link for my file) you can see my edit, which I will also post below:

$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
    $ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
    $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
    $ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
    $ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
    $ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
    $ipaddress = getenv('REMOTE_ADDR');
else
    $ipaddress = 'UNKNOWN';

# Create a new Archive
$zip = new ZipArchive;
# Create the file to archive to
$res = $zip->open($file, ZipArchive::CREATE);
# If create works
if ($res === TRUE) {
    # Create the comment here
    $zip->setArchiveComment(base64_encode($ipaddress));
    $zip->close();
}

Basically it works to append the IP of who downloads it into the zip file, as comment.

As standalone script it works fine, but I'm having a hard time implementing it into the file hosting script, as when the file gets downloaded, it's unmodified.

I suppose the problem is with the variable $file which might not be correct, because as stand-alone script it's enough to specify in there the name of the archive in order to append the comment and then download it, while with the file hosting script, if I assign the variable holding the file name (which is $file->originalFilename), still nothing happens.

Hope you can assist me into properly implementing my script, thank you.

  • 写回答

1条回答 默认 最新

  • doubi6303 2019-02-27 11:27
    关注

    Turned out I was right, the problem was the variable $file which wasn't correct as the script wasn't able to define it as object

    I digged around and found the right variable, holding the full path to the file in the file hosting script which turned out to be:

    $file->getFullFilePath()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么