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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog