|
|
| Author |
Message |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 19:22 - 11 Nov 2010 Post subject: Need some clever php script or something similar. |
 |
|
I need a script I can upload to a websites root and users can click that link and download the entire contents of the public_html folder.
How can this be done? I are not a coding genius and only know basic php and html.
Cheers.
Plenty of for whoever halps. |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
 Posted: 19:39 - 11 Nov 2010 Post subject: |
 |
|
Hi
Would be fairly easy to write.
Script that does a dir, loops through all the files, adds them to a zip file, saves the zip file and then sends the zip to the browser. Maybe be more convenient ways to do it depending on any package you chose to create zip files.
However main reason I can see for this is to upload to victims servers and get the contents remotely.
All the best
Keith ____________________ Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Gazdaman |
This post is not being displayed .
|
 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
 Posted: 20:57 - 11 Nov 2010 Post subject: |
 |
|
Something like this:
| Code: | <?php
if ($handle = opendir('/path/to/files')) {
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?> |
Bastardise that code to loop through a directory and read all filenames into an array. Obviously adding a bit of hocus pocus to check each $file to see if it's a subdirectory itself.
Then use ZipArchive() to add each file from the array into a zip file, then I'd just refresh the page to the URL of the zip file which will make it auto download.
My concern would be that the script could potentially create a MASSIVE zip file, far too big to easily download. Obviously you'd have to create some safeguards so that it always overwrote the previous zipfile, so that if someone naughty found it they couldn't eat up all your spare HDD space.
If you need any help doing it, feel free to give me a PM. I would have put more effort into writing it for you, but I've got an early start in the morning (and therefore can't be arsed).
Gaz
Last edited by Gazdaman on 21:00 - 11 Nov 2010; edited 2 times in total |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Shaggy D.A. |
This post is not being displayed .
|
 The Shaggy D.A. Super Spammer

Joined: 12 Sep 2008 Karma :  
|
 Posted: 20:58 - 11 Nov 2010 Post subject: |
 |
|
If they just want a local copy of their website, then this will work :-
https://www.httrack.com/ ____________________ Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5 |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Gazdaman |
This post is not being displayed .
|
 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Syris the Indomitable |
This post is not being displayed .
|
 Syris the Indomitable Crazy Courier

Joined: 22 Oct 2010 Karma :    
|
 Posted: 09:35 - 12 Nov 2010 Post subject: |
 |
|
https://www.zubrag.com/scripts/download.php ____________________ In Greek mythology Ichor is what immortals have in the place of blood
Those that mind, don't matter...Those that matter, don't mind. Do you agree with this?
Last edited by Syris the Indomitable on 23:14 - 12 Nov 2010; edited 1 time in total |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
 Posted: 15:52 - 12 Nov 2010 Post subject: |
 |
|
Hi
Simple script for you.
| Code: |
<?php
// Array of IP addresses that this can be run from. Basically localhost and the server.
$allowableIp = array("127.0.0.1","127.126.125.124");
if (!in_array($_SERVER['REMOTE_ADDR'],$allowableIp))
{
echo "Bog off";
exit;
}
$dir = "./";
// Open a current directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir))
{
ini_set('max_execution_time', 120);
$filenamezip="Zip/Backup.zip";
$zip = new ZipArchive;
$res = $zip->open($filenamezip, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if ($res === TRUE)
{
while (($file = readdir($dh)) !== false)
{
if ($file != '.' && $file != '..')
{
if (!is_dir($dir.$file))
{
$zip->addFile($dir.$file, $file);
}
}
}
}
$zip->close();
header("Content-disposition: attachment; filename=$filenamezip");
header('Content-type: application/zip');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filenamezip));
@readfile($filenamezip);
@unlink($filenamezip);
closedir($dh);
}
}
?>
|
That reads the current directory and puts each file found in a zip file (stored in a sub directory called Zip), then lobs that file at the user when finished, and deletes it.
Also checks the ip address at the top against a predefined list as some crude security
All the best
Keith ____________________ Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 15:56 - 12 Nov 2010 Post subject: |
 |
|
so if I upload that script to my root and go to it, it will make a zip file in which the entire contents of the website are in and it will download to the users computer?
Awesome.
I am gonna try it now.  |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Gazdaman |
This post is not being displayed .
|
 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 22:21 - 14 Nov 2010 Post subject: |
 |
|
OK done that but it only downloads the files in the root, not all the folders.
Not sure how to modify this script...  |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Gazdaman |
This post is not being displayed .
|
 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 01:33 - 15 Nov 2010 Post subject: |
 |
|
Ok, thanks for all the help but I have no idea what to do
The file system on the site is fairly complex as in, there are lots and lots of files and sub directories.
From what you just said it sounds like I have to add each individual file to the script to backup. |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Gazdaman |
This post is not being displayed .
|
 Gazdaman I did a trackday!!!

Joined: 12 Aug 2004 Karma :    
|
 Posted: 01:38 - 15 Nov 2010 Post subject: |
 |
|
| The Artist wrote: | Ok, thanks for all the help but I have no idea what to do
The file system on the site is fairly complex as in, there are lots and lots of files and sub directories.
From what you just said it sounds like I have to add each individual file to the script to backup. |
No, that's absolutely not what I said.
At the moment it loops through a directory, and if what it finds ISNT a directory, it adds it to the zip file.
What it needs to do, is if it IS a directory, it needs to start the script again, on that directory, so it adds all files in there to it.
But say you have a public_html, with an images folder, and a load of html files index.html and kickoff.html
So it loops through, finds index.html first, adds it to the zip file, then finds the images folder, so goes into that, and adds all files in there to the zip.
You'd need to be careful to make sure it goes back into the public_html folder and still catch the kickoff.html file.
Gaz |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
 Posted: 13:00 - 15 Nov 2010 Post subject: |
 |
|
Hi
Here you go. Updated to do the processing of a directory within a function, with the function calling itself to process any sub directories.
| Code: |
<?php
// Array of IP addresses that this can be run from. Basically localhost and the server.
$allowableIp = array("127.0.0.1");
if (!in_array($_SERVER['REMOTE_ADDR'],$allowableIp))
{
echo "Bog off";
exit;
}
$dir = "./";
// Open a current directory, and proceed to read its contents
ini_set('max_execution_time', 120);
$filenamezip="Backup.zip";
$zip = new ZipArchive;
@unlink($filenamezip);
$res = $zip->open($filenamezip, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if ($res === TRUE)
{
if ($dh = opendir($dir))
{
ProcessDirectory($dh, $dir,$zip);
}
closedir($dh);
}
$zip->close();
header("Content-disposition: attachment; filename=$filenamezip");
header('Content-type: application/zip');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filenamezip));
@readfile($filenamezip);
@unlink($filenamezip);
function ProcessDirectory($dh, $dir, $zip)
{
while (($file = readdir($dh)) !== false)
{
if ($file != '.' && $file != '..')
{
if (is_dir($dir.$file))
{
if($file != "." && $file != "..")
{
if ($zip->addEmptyDir(substr($dir,2).$file))
{
if ($dh2 = opendir($dir.$file.'/'))
{
ProcessDirectory($dh2, $dir.$file.'/',$zip);
closedir($dh2);
}
}
else
{
}
}
}
else
{
if ($file != 'Backup.zip')
{
$zip->addFile($dir.$file, substr($dir,2).$file);
}
}
}
}
}
?>
|
Doesn't need a subdirectory called zip anymore, and will ignore any files called Backup.zip when doing the backup.
All the best
Keith ____________________ Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 14:14 - 15 Nov 2010 Post subject: |
 |
|
Thanks so much. Downloading now, shall see whether it is all there but I think it will be by the size of it.
to everyone in this thread. |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| The Artist |
This post is not being displayed .
|
 The Artist Super Spammer

Joined: 06 Jan 2008 Karma :  
|
 Posted: 17:29 - 15 Nov 2010 Post subject: |
 |
|
It worked. Thanks so much Keith.  |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Tarmacsurfer |
This post is not being displayed .
|
 Tarmacsurfer World Chat Champion

Joined: 29 Jun 2004 Karma :     
|
 Posted: 17:57 - 15 Nov 2010 Post subject: |
 |
|
No advice (you'd get better code from a shit throwing chimp than I can manage) but I feel the need to say -
Keith, you're one of the most genuinely helpful people I've stumbled across in any walk of life. Kudos to you.
 ____________________ I'm immortal. Well, so far. |
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
| Kickstart |
This post is not being displayed .
|
 Kickstart The Oracle

Joined: 04 Feb 2002 Karma :     
|
|
| Back to top |
|
You must be logged in to rate posts |
|
 |
Old Thread Alert!
The last post was made 15 years, 310 days ago. Instead of replying here, would creating a new thread be more useful? |
 |
|
|