bulk image upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

bulk image upload

Post by rubberjohn »

Hi,

Is there a way to upload a large number of images at the same time. Someone told me it is not possible but I'm sure it is.

I'm developing a gallery type site and the photographers can have between 200-600 images and obviously if they have to upload all of these individually it would make the whole thing unworkable.

Don't sites like flickr and facebook let you upload more than one image at the same time?

Basically, is there a way to choose a folder to upload instead of individual files?

Although I think this should be possible, I seem to remember there being some browser limitations that may prevent this.

As opposed to a regular file upload, is it possible to provide the users with a site based ftp facility that would restrict uploads to a certain directory (their subdirectory in the main image directory on the server).

Any help / info is greatly appreciated.

Many thanks for your time.

John
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Re: bulk image upload

Post by rubberjohn »

Thinking about it further - is it possible to provide ftp access to a restricted folder on the server? The idea being, the users then use an ftp client to upload the pics.
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: bulk image upload

Post by ldougherty »

This script will allow you to upload multiple files at once; I use it on a gallery I wrote.

form.php

Code: Select all

 
 
echo "<form enctype='multipart/form-data' action='upload.php' method='POST'>";
echo "<table>";
echo "<input type='hidden' name='album' value='$album'>";
 
for ($x=1;$x<=10;$x++) {
  echo "<tr><td>Select Image:</td><td><input name='uploadedfile[$x]' type='file'></td></tr>";
}
 
echo "<tr><td colspan=2 align=left><input type='submit' value='Upload File'>&nbsp;&nbsp;<input type='reset' value='Reset'></td></tr>";
echo "</table>";
echo "</form>";
 
 
upload.php

Code: Select all

 
 
$album = $_POST[album];
$ufields = '10';         # Number of Upload Fields
 
###############
### BULK UPLOAD
###############
 
 
  for ($x=1;$x<=$ufields;$x++) {
 
    ####################################
    ## CONFIRM UPLOAD FIELD IS NOT EMPTY
    ####################################
 
    if ($_FILES[uploadedfile][name][$x]) {
 
      echo "Processing Field $x<br>";
 
      $fname = basename($_FILES['uploadedfile']['name'][$x]);
      $target_path = $album . '/' . $fname;
 
      $file_ext = substr($fname, strripos($fname, '.'));
      echo "file_ext is $file_ext<br><br>";
      $allowedExtensions = array(".jpg", ".JPG", ".gif", ".GIF");
      if (!in_array($file_ext,$allowedExtensions)) {
        echo "<font color=red><b>FAIL</b></font>: Invalid File Type";
        exit();
      }
 
      if(move_uploaded_file($_FILES[uploadedfile][tmp_name][$x],$target_path)) {
 
        echo "File $fname Uploaded Successfully!<br>";
 
      } else {
 
        echo "Upload of File $fname Failed!<br>";
 
      } # End Check Field
 
  } # End For Loop
 
 
Hope this helps..
Last edited by Benjamin on Mon May 11, 2009 6:45 pm, edited 1 time in total.
Reason: Changed code type from text to php.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Re: bulk image upload

Post by rubberjohn »

That's great. I'll have a play with it now.

Thanks for that, I really appreciate it - I'll let you know how I get on. Cheers.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Re: bulk image upload

Post by rubberjohn »

It does work great but it's not ideal for what I need it for. If you are uploading a relatively small number of photos it would be ideal, however once the number of photos get over a certain size, it would become unworkable.

From what I have been reading, browser based uploads are restricted by size. I think I am restricted to using FTP of some kind, but is there a way to implement it for multiple users and to restrict access to their image folders?
ldougherty
Forum Contributor
Posts: 103
Joined: Sun May 03, 2009 11:39 am

Re: bulk image upload

Post by ldougherty »

The limitations in place are not browser based, they are server based.

In your php.ini you would have values as such..

Code: Select all

 
; Maximum size of POST data that PHP will accept.
post_max_size = 32M
 
; Maximum allowed size for uploaded files.
upload_max_filesize = 32M
 
These two fields determine the size of data that can be uploaded via PHP

You are correct though that if you intend on uploading multiple large scale files using PHPs FTP functions would be your best bet.

http://us2.php.net/ftp
Last edited by Benjamin on Tue May 12, 2009 7:43 pm, edited 1 time in total.
Reason: Added [code] tags.
Post Reply