Hello! I'm very new to PHP, and I need a simple script to let users upload stuff.
On my site, I'll have two different forms, one for uploading pictures and one for uploading video, and so I'll also have two scripts. When the user uploads a picture, it will be saved in the directory "userpics" and videos will go in "uservids".
If someone could give me these scripts, I'd greatly appreciate it!
And if you do, please make it so pictures must be equal to or under one megabyte and jpg, jpeg, png, gif, or bmp, and videos must be equal to or under two megabytes and mp4, avi, asf, wmv, mov, or ogg.
(I can make the forms, by the way, so don't worry about that.)

Thanks a bunch! 😃

    Well yes. :p I guess I'm just having trouble configuring it the way I said I wanted it. I'll keep searching then.

      The way you get better replies is by showing what you have been trying, and letting us know where you got stuck.

      after all.. why should we take the effort to program something for you, if you have not tried, right?

      So.. tell us.. What have you tried, where are you stuck?

      J

        Ok. Well I found a script on w3schools. Here it is:

        <?php
        if ((($_FILES["file"]["type"] == "image/gif")
        || ($_FILES["file"]["type"] == "image/jpeg")
        || ($_FILES["file"]["type"] == "image/pjpeg"))
        && ($_FILES["file"]["size"] < 20000))
          {
          if ($_FILES["file"]["error"] > 0)
            {
            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
            }
          else
            {
            echo "Upload: " . $_FILES["file"]["name"] . "<br />";
            echo "Type: " . $_FILES["file"]["type"] . "<br />";
            echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
            echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
        
        if (file_exists("upload/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
          }
        }
          }
        else
          {
          echo "Invalid file";
          }
        ?>

        And I can add all the file extensions I wanted, and change the max file size, but I also want the persons name to be submitted with the picture... like maybe the script would create a folder in the upload directory with a .txt file holding the person's name, and their picture. I also don't need it to say all the extra info about the upload once it's been uploaded. I just want it to say "Thanks for uploading" or something.

          The section:

              echo "Upload: " . $_FILES["file"]["name"] . "<br />";
              echo "Type: " . $_FILES["file"]["type"] . "<br />";
              echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
              echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

          gives the extra info to which I assume you are referring. Therefore, just change it to:

          echo "Thanks for uploading";

          Do your users log in, or is this an anonymous uploader? If they log in, you could retrieve the user name, and have it create a directory. For example, if your user name were stored in the string $username, you could change any occurence of:

          "upload/" . $_FILES["file"]["name"]

          to:

          "upload/" . $username . "/" . $_FILES["file"]["name"]

          Even if you don't have a user, you could have a form with an input box, and use the value from that form in the same manner. I assume you know how to do that, as you mentioned you can do the forms. You could do it with the same code I just gave you, and somewhere above that declare the string, e.g.:

          $username = $_POST["whateverYourFormTitleIs"];
            Write a Reply...