dongyu2047 2011-06-09 19:34
浏览 56
已采纳

上传PHP文件和上传zip

Does anyone know of a good way to upload a file (.mp3 or .wav or .txt or .whatever) and zip this file before being moved to the directory?

So the user uploads a .mp3 file, before this file is moved to the specific directory it will be zipped and then moved.

Please advise.

Thank you

  • 写回答

2条回答 默认 最新

  • dsfe167834 2011-06-09 19:39
    关注

    Take a look at the Zip extension:

    http://www.php.net/manual/en/zip.examples.php

    I looked at the code you linked to (it would have been good if you included it in the question) and made a few changes:

    $nameFile = $_FILES['file']['name'];
    $tmpName = $_FILES['file']['tmp_name'];
    $download_folder = './files/';
    
    $zip = new ZipArchive();
    $fileconpress = $download_folder.$nameFile.".zip";
    
    $conpress = $zip->open($fileconpress, ZIPARCHIVE::CREATE);
    if ($conpress === true)
    {
        $zip->addFile($tmpName);
        $zip->close();
        echo $fileconpress."<br/>";
        echo "yess !! Success!!!! ";
    }
    else echo " Oh No! Error";
    

    The important part and likely what's causing your error is $download_folder. You need to define the path of where you want to save the file.

    I also removed the fread(), you can just load the file straight into the zip object with addFile()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程