Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP's unzip() not unzipping.

Status
Not open for further replies.

ingernet

Programmer
Feb 5, 2001
68
US
Hi folks,

After working on this for 3 hours, I've decided to bite the bullet and ask for help.

I've got a file that I'm uploading through a form - the file is called myfile.zip. For what it's worth, it was created on Mac OSX using the "Make an Archive" option.

I know that it's a valid ZIP format because when I'm in the shell, I can type:

Code:
/usr/[URL unfurl="true"]www/users/inger/admin/%[/URL] unzip myfile.zip

And voila, it's unzipped. No complaints from the server.

But when I use PHP to do this -

Code:
chdir ("/usr/[URL unfurl="true"]www/users/inger/admin/tempfiles/");[/URL]
chmod ("myfile.zip", 0755);
shell_exec("unzip myfile.zip") or die("couldn't unzip file!");

- well, it dies.

2 questions:

1. WTF? I don't think it's a permissions thing because Apache (nobody) has write access to the tempfiles dir (it's chmod'ed 777 to remove that variable):

Code:
% ls -ld /usr/[URL unfurl="true"]www/users/inger/admin/tempfiles[/URL]
drwxrwxrwx  2 inger  users  512 Apr 27 15:54 .

Anyone else have any idea why PHP won't unzip the file?

2. I simply LOVE the mysql_error() function - is there an equivalent for filesystem errors? (I tried using trigger_error(E_USER_ERROR) and was underwhelmed by the information it provided.)

Thanks for your help. There are so many knowledgeable and creative people on this list.

Inger
 
I would suspect that this is a path problem.

In this line:

shell_exec("unzip myfile.zip") or die("couldn't unzip file!");

you probably need to include the absolute filesystem path to unzip:

shell_exec("[red]/usr/bin/[/red]unzip myfile.zip") or die("couldn't unzip file!");







Want the best answers? Ask the best questions! TANSTAAFL!
 
As to your second question....

shell_exec() returns a string that is the output of the command. Often, that string will contain error output from the command shell or the application when something goes wrong. Has this string been empty for you?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Who rocks?

Sleipnir214 rocks!

That was the trick. I'm doing a happy dance. Thanks for your help.

Inger
 
Hey ingernet,

I have a question or two about this that you may be of assistance with - Am I right in assuming that you have already uploaded the file and when a user clicks on the button for the zip (it will automatically "unzip" it?)

I have a client, in their own (seemingly proud) offhand description of themselves, are "computer illiterate" --- and every time (I mean EVERY) time I try to send them a file by email, or upload a zipped copy to a server, or have placed in a html file.... they cant seem to get it!

They don't have winzip and refuse to get it, they dont have the ability to copy a file to the clipboard, and.... they try to doubleclick a pdf (refuse to get the Reader) on their disk and are dismayed that they can't "open" the file -- all very frustrating. So I figure they can drag a jpg to a browser window and look at it there....

This brings me to my point... is this a clickable button on a page that will "unzip" a file from a server? If it does..... could you share it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top