I'm working on a picture database. I want to upload a whole folder with .jpg's to the website. I know how to upload one file, but how do I upload a whole folder at once? Can someone please show me a code example?

    I've haven't done this before ... but there are three things I could do off the top of my head:

    1. Open IE and drag and drop the folder
    2. Use the OS's built in FTP with the command mput
    3. Create a script and run it locally to iterate the folder and upload each file (PHP needs to be running locally).

      It feels like I did not explain myself correctly. There is no problem to upload the folder with a ftp app or other method. The only thing I am interested in is:

      How do you do it from a PHP script?

      So your number 3 is the way I'm interested in, except that you run it locally. Let me explain:

      The user should be able to select a folder on the harddrive by using my script at my domain, and when he clicks all files in that folder will be uploaded to my domain. So I don't want a html form where the user select several files, and then upload them. And the most important thing, the script must be located at my domain, the same place where all the files in the folder will be uploaded.

      So maybe I need some sort of web based ftp upload function in my script.

      Look at this code:

      In the file form.html

      <form action="upload.php" method="post" ENCTYPE="multipart/form-data">
      File: <input type="file" name="file" size="30">
      <input type="submit" value="Upload!">
      </form>

      In the file upload.php

      <?php
      // ==============
      // Configuration
      // ==============
      $uploaddir = "uploads";
      // Where you want the files to upload to
      //Important: Make sure this folders permissions (CHMOD) is 0777!
      // ==============
      // Upload Part
      // ==============
      if(is_uploaded_file($FILES['file']['tmp_name']))
      {
      move_uploaded_file($
      FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
      }
      print "Your file has been uploaded successfully! Yay!";
      ?>

      This is the normal way to upload 1 file. The only thing I need is to take away the html file and iterate a folder instead. And make a loop in the php script so it uploads all files.

      But I don't know how to do it so I need help.

        Write a Reply...