Substituting variable for filename


Hello. I am trying to create a script that presents you with a textbox where you enter the name of a .zip, .tgz, or .tar.gz file in that directory on your server. Then, it decompresses it one the server. Here is the script:

$filename = $_GET[‘filename’];
if (empty($filename))

<?php }

if (strpos($filename,".zip") >= 1)
exec(‘unzip $filename’,$ret);
echo “Successful unzipping”;
elseif ((strpos($filename,".tgz") >= 1) || (strpos($filename,".tar.gz") >= 1))
exec(‘tar -xzf $filename’,$ret);
echo “Successful untargzing”;

<?php } } ?>[/code]

On the two exec lines, if I replace $filename with the actual name of a compressed file on my server, it will successfully decompress it, but if I leave it the way it is and enter that file’s name in the textbox, it will not work. Why isn’t it decompressing?


Inside single quotes, PHP variables arn’t parsed:

$foo = “world”;

echo ‘Hello $foo’; // echoes: Hello $foo
echo “Hello $foo”; // echoes: Hello world
echo "Hello ".$foo; // echoes: Hello world

On a sidenote: we’d rather see questions about the same piece of code in one thread, not three.


I should have caught that! Thank you. Also, I apologize. I assumed that since my posts were about diffent problems… but I’ll keep that in mind for the future.


No problem, just trying to keep the forums a bit clean :slight_smile: