You are here: Re: using shell_exec question « PHP Programming Language « IT news, forums, messages
Re: using shell_exec question

Posted by Paul on 12/18/95 11:48

On Tue, 2006-05-23 at 10:16 +0000, Andy Jeffries wrote:

> What I would do is change your code to be as follows:
>
> $command = "zip -9 $fn[$id].zip $files";
> header("content-type:application/zip");
> header("Content-disposition: attachment; filename=$fn[$id].zip");
> header("Pragma: no-cache");
> header("Expires: 0");
> shell_exec($command);
> @readfile("$fn[$id].zip");
>
> In this, all I've done is change a few bits to make use of variable
> substitution within a string (concatenation is faster but looks a lot less
> readable) and then added a call to readfile at the end, which reads a file
> from disk and prints the contents to the browser.

Okay, I've done that, but it's now giving an empty file of 0 bytes in
length.

The new code looks like this

<?php
chdir ('../downloads');
$pid = $_GET['id'];
$pid--;
$courses=array("hndmp", "batar", "bamlb", "bscmt", "bajor");
$counter = count($courses);
if ($pid > $counter)
exit;
$prog = $courses[$id];
$filenames = array($prog."fc.pdf", $prog."1-3.pdf", $prog."5-6.pdf");
$prog .= ".zip";
$command = "";
for ($i = 0; $i < $counter; ++$i)
$command .= "zip -9 $prog $filenames[$i];";
header("content-type: application/zip");
header("content-disposition: attachment; filename=$prog");
header("pragma: no-cache");
header("expires: 0");
shell_exec($command);
@readfile("$prog");
?>

As a test, I added an echo line after the for loop and the output was
expected (the created zip file was actually a text file with the echo
output inside of it). Changing @readfile to readfile showed that the
file hadn't actually been created.

Now, if I change where $prog is to be /tmp/$prog, I hit an interesting
problem, the file is created, but the permissions are for apache:apache
rather than myself and obviously, chown won't work (unless I sudo it).
Have I hit more a permissions problem than a php one?

TTFN

Paul
--
"Logic, my dear Zoe, is merely the ability to be wrong with authority" -
Dr Who

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация