dtdt0454 2012-09-21 14:35
浏览 195
已采纳

tar文件保留完整路径。 怎么阻止它?

I am trying to create a tar archive on my server through PHP as follows:

exec('tar -cvf myfile.tar tmp_folder/innerfolder/');

It works fine, but the saved file preserves the full path including tmp_folder/innerfolder/ I am creating those on the fly for users, so it's a bit unusable for users to have this path while extracting. I have reviewed this topic - How to strip path while archiving with TAR , but in the explanation the guy doesn't give an example, and I don't quite understand what to do.

Please, tell me with an example, how to add files to tar in a way that it does not preserve the 'tmp_folder/innerfolder/' part in archive?

Thanks in advance

  • 写回答

5条回答 默认 最新

  • douluo5937 2012-09-21 14:39
    关注

    you can cheat..

    exec('cd /path/to/tmp_folder/ && tar -cvf /path/to/myfile.tar innerfolder/');
    

    This would would give your users just the innerfolder when they extracted the tarball

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

报告相同问题?