Jump to content

Unzipping Root Server


pstoneham

Recommended Posts

I have a Linux root server with 1&1. Using a daily CRON job calling a PHP script I want to :-

 

 

1)            Connect to another server via FTP

 

2)            Download a zipped XML file from the other server to a folder on my root server

 

3)            Unzip the file

 

4)            Read the XML file and extract relevant data into my MySQL database

 

 

I have succeeded with points 1 and 2 using the following script (call it myscript.php) :-

 

<?php

 

 

define ('FTP_SERVER', 'theotherserver');

 

define ('FTP_USERNAME', 'username');

 

define ('FTP_PASSWORD', 'password');

 

 

 

$ftp = ftp_connect(FTP_SERVER);

 

$bResult = ftp_login($ftp, FTP_USERNAME, FTP_PASSWORD);

 

 

 

$contents = ftp_nlist($ftp, "/dir");

 

for ($i = 0; $i < count($contents); $i++)

 

{

 

echo ($contents[$i]."<br>\n");

 

}

 

 

 

$getFile = '/dir/filename.zip';

 

ftp_get($ftp, "downloads/filename.zip", $getFile, FTP_BINARY);

 

ftp_close($ftp);

 

 

 

?>

 

 

 

The zipped XML file ends up being downloaded into a folder called /downloads which has CHMOD settings of 777 so the structure looks something like this :-

 

 

 

myscript.php

 

                /downloads/filename.zip

 

 

 

Now comes the tricky bit. I want to unzip the file. I added a line to myscript.php which looked something like this :-

 

 

 

<?php

 

unzip ("downloads/filename.zip", "downloads/unzipped.txt")

 

?>

 

 

 

This didn't work so I also tried other formats (backslashes, just the filename, different extension for the destination file etc. etc.) Still nothing !

 

 

 

It occurred to me that maybe the "unzip" command was not one recognised by Apache, so using PuTTy and a SSH connection I logged into the root server (as root) and browsed to the downloads folder. Then I typed "unzip filename.zip" at the command line and hey presto it unzipped perfectly. So I now know that the server has the tools I need to unzip the file. What I don't understand is how to get PHP to do it for me.

 

 

 

I have a couple of hunches :-

 

 

 

1) PHP needs to use full path names in relation to Apache

 

2) Safe mode settings need changing

 

 

 

I've tried various path name such as /var/www/vhosts/mydomain/downloads/filename.zip but still no joy.

 

 

 

I've tried amending my PHP.INI file to switch Safe Mode off but this doesn't work either (php_info shows Safe Mode as On for Local ?? and Off for Master) I've no idea what that means !!

 

 

 

Until I can get CRON/PHP to unzip my downloaded file I can't finish this job so I'm getting kind of desperate now. I'm fairly good with root server management etc. but I'm not an "expert" as it were, my main field being PHP coding so if there is anyone who understands how Apache/PHP/unzip etc works I'd be very grateful to hear from them.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.