Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Need some clever php script or something similar.

Reply to topic
Bike Chat Forums Index -> The Geek Zone Goto page 1, 2  Next
 Topic moved: from Random Banter to The Geek Zone by G (11 Nov 2010 - 19:06)
View previous topic : View next topic  
Author Message

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 19:22 - 11 Nov 2010    Post subject: Need some clever php script or something similar. Reply with quote

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 Karma for whoever halps.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 19:39 - 11 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 20:45 - 11 Nov 2010    Post subject: Reply with quote

It is for a site I built for someone else and they want an offline backup.

Rather than post a flash disk or upload the site from my PC, (my internets speed is crap) can I do this somehow?

I can't write code, only alter it. Surely there must be a ready made script out there for this.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 20:57 - 11 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

The Shaggy D.A.
Super Spammer



Joined: 12 Sep 2008
Karma :

PostPosted: 20:58 - 11 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 20:59 - 11 Nov 2010    Post subject: Reply with quote

I dunno why they can't just use FlashFXP.

Obviously a script like this won't grab any associated SQL databases.

Gaz
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 20:59 - 11 Nov 2010    Post subject: Reply with quote

Hi

Not sure. I can probably knock something up for you (not at this moment, using the Mac with no useful development environment on it).

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 21:34 - 11 Nov 2010    Post subject: Reply with quote

If someone could make a script I would be really grateful.

I would use that program shaggy but the guy who is downloading the site is not computer literate at all.

He can follow instructions over the phone but that is it.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Syris the Indomitable
Crazy Courier



Joined: 22 Oct 2010
Karma :

PostPosted: 09:35 - 12 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 15:52 - 12 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 15:56 - 12 Nov 2010    Post subject: Reply with quote

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. Karma Karma
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 16:05 - 12 Nov 2010    Post subject: Reply with quote

Ok it says the zip file is invalid.

I had a look through that script Keith and tbh I don't really understand it. I can follow it kind of but wouldn't know how to change it to work.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 17:32 - 12 Nov 2010    Post subject: Reply with quote

Hi

You need to create a sub directory called Zip.

The script is pretty simple. I can talk you through it if you want.

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 22:30 - 12 Nov 2010    Post subject: Reply with quote

Elegant.

Gaz
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 22:21 - 14 Nov 2010    Post subject: Reply with quote

OK done that but it only downloads the files in the root, not all the folders.

Not sure how to modify this script... Confused
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 01:09 - 15 Nov 2010    Post subject: Reply with quote

There's all the info there to modify it.

if (!is_dir($dir.$file))
{
$zip->addFile($dir.$file, $file);
}

That piece of code, if you add an else to that if clause, that'll function if the file is a directory.

You could make the initial script as a function, then you could execute the function within that line of code, so it'll run the whole thing again on the sub directory. It might need a bit more work, to make sure that it goes back to the files after the sub directory in the folder.

Gaz
 Back to top
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 01:33 - 15 Nov 2010    Post subject: Reply with quote

Ok, thanks for all the help but I have no idea what to do Embarassed

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
View user's profile Send private message Send e-mail You must be logged in to rate posts

Gazdaman
I did a trackday!!!



Joined: 12 Aug 2004
Karma :

PostPosted: 01:38 - 15 Nov 2010    Post subject: Reply with quote

The Artist wrote:
Ok, thanks for all the help but I have no idea what to do Embarassed

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
View user's profile Send private message Send e-mail Visit poster's website You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 01:43 - 15 Nov 2010    Post subject: Reply with quote

I must sound like a complete n00b here but how do I get it to do that?

Like I said I can't code, just alter basic stuff.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 13:00 - 15 Nov 2010    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 14:14 - 15 Nov 2010    Post subject: Reply with quote

Thanks so much. Downloading now, shall see whether it is all there but I think it will be by the size of it.

Karma Karma to everyone in this thread.
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 15:16 - 15 Nov 2010    Post subject: Reply with quote

Hi

Hope it fixes it. If it times out (possible if it is a large web site, adding a 20mb zipped file to the backup seemed to cause time issues when testing) then up the time limit a touch (set to 120 seconds in that script).

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

The Artist
Super Spammer



Joined: 06 Jan 2008
Karma :

PostPosted: 17:29 - 15 Nov 2010    Post subject: Reply with quote

It worked. Thanks so much Keith. Karma Karma Thumbs Up
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Tarmacsurfer
World Chat Champion



Joined: 29 Jun 2004
Karma :

PostPosted: 17:57 - 15 Nov 2010    Post subject: Reply with quote

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.

Karma
____________________
I'm immortal. Well, so far.
 Back to top
View user's profile Send private message You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 18:42 - 15 Nov 2010    Post subject: Reply with quote

Hi

Thank you. I try although I think I fail a lot of the time.

All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail 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?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.10 Sec - Server Load: 0.65 - MySQL Queries: 16 - Page Size: 140.1 Kb