4 Replies - 1684 Views - Last Post: 24 January 2009 - 03:23 PM Rate Topic: -----

#1 xalu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-October 08

Need help with zip files and images

Posted 24 January 2009 - 01:22 PM

Hey I was wondering if someone could help me add an Unzip funtion to my upload script. Also add the option for more then one upload at once. heres what I am working off of http://www.zymic.com...-form-with-php/

My upload script is as follows:

<?php
   // Configuration - Your Options
	  $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.GIF','.BMP','.PNG','.zip','.rar'); // These will be the types of file that will pass the validation.
	  $max_filesize = 5242880; // Maximum filesize in BYTES (currently 5MB).
	  $upload_path = './Images/'; // The place the files will be uploaded to (currently a 'files' directory).
	  $gallery_path = '';  // The place the files will be displayed.

 
   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
	  die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
	  die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
	  die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
		 echo 'Your file upload was successful, view the file <a href="gallery.php  " title="Your File">here</a>'; // It worked.
	  else
		 echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
 
?>


Thanks!!!

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with zip files and images

#2 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: Need help with zip files and images

Posted 24 January 2009 - 01:37 PM

Scale is a word that comes to mind. If this is a simple app, then to unzip in php, I think the ZZIPlib module would be a place to start. There are some tutorials on google.

However, I would say that php isn't really meant for intense parsing like this, and you may run into corrupted files (by execution time or other anomalies) or a deadlock on your server.

What you would want to do, is create a shell script that unzips and outputs the compressed files in your uploaded directory and delete the archive. You can setup a cron job to run this script every so often.

Don't forget security, as an attacker could upload a c99.php ( 5 pnts to whoever gets the reference) and when you shell script unzips that archive, without checking the extracted file, you have a compromised machine.

Remember, when you allow someone to upload to your machine, your giving them almost raw access, so make sure you tripple check what they are doing before you allow what they upload to be stored.
Was This Post Helpful? 0
  • +
  • -

#3 xalu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-October 08

Re: Need help with zip files and images

Posted 24 January 2009 - 01:48 PM

View Postjoeyadms, on 24 Jan, 2009 - 12:37 PM, said:

Scale is a word that comes to mind. If this is a simple app, then to unzip in php, I think the ZZIPlib module would be a place to start. There are some tutorials on google.

However, I would say that php isn't really meant for intense parsing like this, and you may run into corrupted files (by execution time or other anomalies) or a deadlock on your server.

What you would want to do, is create a shell script that unzips and outputs the compressed files in your uploaded directory and delete the archive. You can setup a cron job to run this script every so often.

Don't forget security, as an attacker could upload a c99.php ( 5 pnts to whoever gets the reference) and when you shell script unzips that archive, without checking the extracted file, you have a compromised machine.

Remember, when you allow someone to upload to your machine, your giving them almost raw access, so make sure you tripple check what they are doing before you allow what they upload to be stored.

Hmm well two points.

I dont really know how to set up a script to unzip the files. I would much rather have it done instantly with the upload process.

Security isn't a concern in this case as the uploaded files are going to be done behind closed doors in a password protected environment.

If anyone could point me to a tutorial or help with including PHP or something similiar I would be very grateful. I tried finding some Tutorials but I couldn't figure out how to "attach" them to my upload script.
Was This Post Helpful? 0
  • +
  • -

#4 xalu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-October 08

Re: Need help with zip files and images

Posted 24 January 2009 - 02:37 PM

Hey, I got it to work. using a code I found.

  
 //Unzip
  require_once('pclzip.lib.php');  
  $archive = new PclZip($upload_path . $filename);  
  if (($v_result_list = $archive->extract(PCLZIP_OPT_PATH, './Images')) == 0) {  
	die("Error : ".$archive->errorInfo(true));  
  }  
 echo "<pre>";  
  var_dump($v_result_list);  
  echo "</pre>";  



I added this to the end of the above php file. Could someone help me set up an IF statement that would only use this zip command for a .zip file. I don't want it to always do it because if someone just wants to upload a .jpg or something. I don't want errors coming up. If its not possible I could make a seperate form and upload for just .Zip files.

Thanks. oh and getting this stuff to work is so rewarding haha.
Was This Post Helpful? 0
  • +
  • -

#5 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: Need help with zip files and images

Posted 24 January 2009 - 03:23 PM

joeyadams said:

Don't forget security, as an attacker could upload a c99.php ( 5 pnts to whoever gets the reference) and when you shell script unzips that archive, without checking the extracted file, you have a compromised machine.

im guessing you mean the c99 php shell?

This post has been edited by Auzzie: 24 January 2009 - 03:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1