I am creating a script that creates a subdomain on a whm server and then uploads a zip through ftp to it. That part is working fine and my newly created subdomain functions properly and the file I want gets transfered to it.
All I need is to unzip this file. One can easily do it using cpanel's built in file manager but I need this done in my own script. Is there some way to invoke cpanel's zip extraction functionality from my script?
Using PHP's ZipArchive is a problem because it's open() and extractTo() functions cannot take url as argument and the zip file I am talking about is not located in a place that I can access without a url. Here's why:
While I am logged in with cpanel_user_1 I created a subdomain that belongs to it's newly created user (let's say cpanel_user_2). I cannot just open the files in cpanel_user_2's public_html folder because that's the way cpanel works - I don't have access to another cpanel user's files. If ZipArhive could work with url I would just do:
$zip = new ZipArchive;
$zip->open('http://subdomain.domain.com/some_zip.zip')
$zip->extractTo('http://subdomain.domain.com/folder/some_zip.zip');
$zip->close();
But it doesn't... and I don't have access to the actual file path of the file.
Related
I'd need to define a folder where a downloaded files is placed.
Is it possible to achieve a download into a specific folder using the force_download() function, of Codeigniter's framework?
force_download() is part of CI download helper
Generates server headers which force data to be downloaded to your
desktop. Useful with file downloads. The first parameter is the name
you want the downloaded file to be named, the second parameter is the
file data.
that said, a file will be downloaded to your designated download folder, wherever that is on your local disk. You can use this approach to make files downloadable for any user
what you are looking for is to use the CI FTP Class:
Downloads a file from your server. You must supply the remote path and
the local path, and you can optionally set the mode. Example:
$this->ftp->download('/public_html/myfile.html', '/local/path/to/myfile.html', 'ascii');
you must make sure that each time you call this to have the user supplying you with a valid local path, where the downloaded files will be stored.
I cannot believe this hasn't been asked before, but I cannot find the answer on stackoverflow, please redirect me if this is a duplicate and I'm too retarded to find it.
I am creating a script that will download a kmz file from my custom google map, then will unzip it, read the xml and create a web page that lists all my markers. But I don't have access to the servers to create a writable folder so where can I download the kmz file to then unzip it?
Tried the temp folder (/var/tmp) and it seems to download the file, but I cannot work on the file afterwards or extract it, probably because the file gets deleted right after I call fclose, after downloading, as it doesn't exist anymore if I scan the directory.
UPDATE:
To answer question, the file is immediately deleted because it is a shared server and there are tons of session files in that folder that are created by all the visitors of each websites
I would be grateful for help concerning this issue:
User clicks on a link:
the link itself has the parameter that tells which file needs to be unzipped to /unzip folder. After a file is unzipped, I would like to open the file.
How can I do this? I have the unzip part coded already.
I can suggest a following solution:
You create a folder on the server where you will unzip the files to.
You create an .htaccess file there which specifies your own php script as 404 Error handler
In your php script you parse URL and identify which file to unzip, unzip it and redirect user to the newly created file
If you need to clean the unizpped files, you can create a cronjob which will remove files older than a certain time
What you get from that is:
File transfer from server to user is handled by web server
You actually cache your work as 404 handler won't run if you have the file in place
You can significantly lower the server load as this approach reduces the amount of operations performed on server side (when file exists)
The description above assumes Apache as a web server
I am trying make a php script to list the files of a folder above my web directory...I follow a small thing I found here which talked about
a symlink pointing to /var/uploads
a Apache Alias directive Alias /uploads /var/uploads
I did both of these.
$myDirectory = opendir("/var/stuff/stuff/");
That directory there links to like when I go in winscp and click that folder it directs me to it....and when I run my script to list all files inside /var/stuff/stuff/ it lists what is in /home/stuff/stuff.
The thing is when I click the links that it produces I get a not found on the server
The requested URL /stuff was not found on this server.
Would someone please be able to assist me with this?
Since the files are not under the root directory, you will not be able to download them directly, but What you can use for this issue is to create a downloader gateway.
I'll explain:
create a php script somewhere in your app, lets call it downloader.php
the downloader script would get a parameter, lets say: filename
now we could call the script like: http://YOUR-URL/downloder.php?filename=file-to-download
in your downloader.php file you can get the file name, read it from the file system, then force it to be downloaded by out puting its content and configure the correct headers
I'm not sure if you still need that but, if you need more assistance I can help you more with some code samples
ideally you can use .htaccess to hide your downloader gateway script
I have designed an online editor with which a user can create files and folders on the server. Suppose a user creates the below files and folders.
/docs/abc.txt
/docs/def.txt
/docs/work/assignment.txt
I want to write a PHP script to combine the files into a single ZIP file so that it makes it easier for the user to download them with one click.
The only purpose is that I should get a single file with the directory hierarchy maintained which the user can download and uncompress on his system to get the original files and directory structure back. I don't care even if the ZIP file is not compressed.
Note that I am using a shared server and do not have access to execute external commands.
ZipArchive class is what you need. Using this you can add directories and file to an archive.
This is a common requirement and has been solved. Try and check out this class: http://www.phpclasses.org/browse/package/2322.html
More tutorials at:
http://davidwalsh.name/create-zip-php <-- this has a similar example if you scroll down
http://www.w3schools.com/php/php_ref_zip.asp
Assuming you have permission to execute an external command, you could use exec to run an external command-line capable ZIP program such as 7-Zip.