PHP Script to Download, Upload and Uncompress on FTP is easy with a PHP script. It can download from source, uncompress any thing including WordPresslike CMS. Please take the fact that this is actually not a script providing article, the target of this guide to write a PHP Script to Download, Upload and Uncompress on FTP is to make anyone understand, PHP is not very difficult, many modification can be done as per your need.
Basics you will need to code PHP Script to Download, Upload and Uncompress on FTP
For this guide it is quite obvious that you need a Server with FTP or SFTP access. Shell access is not need. You can use any advanced Text Editor like Gedit. Windows users can also can use Gedit. This is due to the fact they support Syntax Highlighting feature.
Basics for PHP Script to Download, Upload and Uncompress on FTP
The major problem is, many Open Source Project do not have the rightly configured url for download link. For example, WordPress always makes it latest.tar.gz for any version. So practically to get the URL, you have to browse to the official Website and get the URL manually. For WordPress you can download such a ready made php script to Download, Upload and Uncompress on FTP from our guide Automate Uploading and Uzipping WordPress on Rackspace Cloud Sites. This will obviously give you the way how to use it.
---
If you open Gedit and create a new blank file with the name upload.php then, depending on your configuration / settings, PHP Script will automatically get Syntax Highlighting.
Basic targets to write the PHP Script to Download, Upload and Uncompress on FTP :
- Download it from official URL as compress folder and upload to SFTP. This is actually done by wget in case of Shell.
- Umcompress it. Equivalent to tar -xzvf function in shell.
- Delete the original file, Equivalent to rm with name of the file.
This is how we can do which is simplified from posteet.com/view/1079 :
1 | <span style="color: #993300;"><?php</span> |
1 | <span style="color: #99cc00;">$url</span> <span style="color: #993300;">=</span> <span style="color: #ff00ff;">"http://download.wikimedia.org/mediawiki/1.19/mediawiki-1.19.2.tar.gz"</span><span style="color: #993300;">; </span> |
1 | <span><span style="color: #0000ff;">// Use the latest url within " marks, you can delete these blue lines</span> </span> |
1 | <span style="color: #99cc00;">$file</span> <span style="color: #993300;">=</span> |
1 | <span style="color: #993300;"><span style="color: #ff00ff;">"mediawiki-1.19.2.tar.gz"</span>; </span><span style="color: #0000ff;">// We are using a short name in above line</span> |
1 | <span style="color: #99cc00;">$esc</span> <span style="color: #993300;">=</span> |
1 2 3 4 | escapeshellarg(<span style="color: #99cc00;">$url</span>)<span style="color: #993300;">;</span> exec("wget " . <span style="color: #99cc00;">$esc</span>); <span style="color: #99cc00;">$shell</span> <span style="color: #993300;">=</span> <span style="color: #ff00ff;">"tar -xzvf <span style="color: #99cc00;">$file</span>"<span style="color: #800000;">;</span> </span> <span style="color: #0000ff;">//as the file is tar.gz we will use </span><span style="color: #0000ff;">$shell = "unzip $file"; </span> |
$shell = escapeshellcmd($shell);
exec($shell,$nu);
$del = “rm $file“;
1 | <span style="color: #99cc00;"><span style="color: #0000ff;">// We need to delete it</span> $del</span><span style="color: #993300;"> =</span> escapeshellcmd(<span style="color: #99cc00;">$del</span>)<span style="color: #993300;">;</span> |
1 | exec(<span style="color: #99cc00;">$del</span>,<span style="color: #99cc00;">$nu</span>)<span style="color: #993300;">; <span style="color: #0000ff;">// This will show the word Complete at the end of operation</span> </span> |
1 | print_r(<span style="color: #ff00ff;">"Complete!"</span>)<span style="color: #993300;">;</span> |
1 | <span style="color: #993300;">?></span> |
Like This is your gedit :

This PHP Script to Download, Upload and Uncompress on FTP does the work, but its painful to use. We can reduce the pain by using a form action like this to get a HTML. If you can do it, you will see it is very easy, but some people sells them in Code Canyon like website as premium scripts ! PHP itself is free, for this small lines, is it really honors Open Source ?
