Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ok I don't really want to waste any more time on investigating this but I do want to offer a .tar option for download instead of just zip.

    $archive = "/home/stevenbu/public_html/temp/".$twitter_name.".tar";
    $directory = "/home/stevenbu/public_html/temp/".$twitter_name;
    exec("tar -cf $archive $directory");

The problem is that when I extract the .tar it is 5 folders deep I would like no folders and just the files in the .tar

Many thanks

share|improve this question

migrated from stackoverflow.com May 23 '11 at 13:38

This question came from our site for professional and enthusiast programmers.

    
Not really a PHP question, more of a tar question. –  AJ. May 23 '11 at 13:31
    
and tar doesn't have a 'junk folders' option... –  pavium May 23 '11 at 13:37
    
While not directly related to your question, always consider the possibility that someone enters $(rm -rf ~) as their Twitter name. –  grawity May 23 '11 at 15:00
    
@AJ It is PHP related as it's run from php exec and not directly. Which does make a difference in certain situations. @grawity Thanks for the heads up, but Twitter would not let you have that name and users must authenticate with twitter to use the script. The twitter name comes from me not from them. –  StevenBullen May 23 '11 at 15:13

2 Answers 2

up vote 1 down vote accepted

It's been a while since I last used php, but

exec("cd /home/stevenbu/public_html/temp/;tar -cf $archive $directory");

would help in shell.

share|improve this answer
    
This does work but instead I needed to use && instead of ; otherwise it went back to the default directory. exec("cd /home/stevenbu/public_html/temp/;tar -cf $archive $directory"); –  StevenBullen May 23 '11 at 15:09
$parent = "/home/stevenbu/public_html/temp";
$dir = $twitter_name;
$archive = $twitter_name.".tgz";

exec('tar -cz -f '.escapeshellarg($archive).' -C '.escapeshellarg($parent).' '.escapeshellarg($dir));

This one is slightly better, because it outputs the .tar.gz file directly to the browser, instead of creating a temporary file:

$parent = "/home/stevenbu/public_html/temp";
$dir = $twitter_name;
$archive = $twitter_name.".tar.gz";

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.addslashes($archive).'"');
passthru('tar -cz -C '.escapeshellarg($parent).' '.escapeshellarg($dir));
share|improve this answer
    
Thanks will test this out shortly. –  StevenBullen May 23 '11 at 15:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.