Results 1 to 6 of 6

Thread: upload video into folder then post

  1. #1
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default upload video into folder then post

    hey everyone does anyone know how to do this:

    1. have a form that uploads video/pictures to a folder.
    2. then a script taht displays uploaded content on page automatically by reading out of uploaded folder.
    3. i want to try this without using mysql. will use mysql if last resort.
    any help is much appreciated. I have a baby website and would like to be able to have family upload ther photos and pics and have them auto populate. thank you so much for any help

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. Look at basic PHP uploads. The form will be easy to write with it.
    Official site (sorta techno-jargon): http://www.php.net/manual/en/features.file-upload.php
    Good tutorial: http://www.php-mysql-tutorial.com/php-mysql-upload.php
    However, that tells you how to load it INTO the database. That's really a bad idea. You should move the file to a folder on the server, then store a path to it. The DB will run smoother and you can download the file directly, then.

    2. There are a few ways. The second link above will tell you how with a database (look at the main site for a general tutorial if you need it).
    Otherwise, you can use the directory/file functions with PHP to do this:
    opendir(); readdir(); file_get_contents(); is_dir(); file_exists(); and others.
    Look them up on the search field near the upper right on www.php.net

    3. Ah. No mysql. That's alright. Don't disregard that php-mysql tutorial above, though. Still gives some good insight to the PHP stuff.
    opendir/readdir, then will help you locate your files.
    It's a much better idea, probably, to use a database than to try to store chunks of data in text files if you were to need to keep records of stuff, but if you can just organize the files in the right folders (ie, a folder per user), then you can avoid that.

    Just for picture uploading / populating, that won't be too bad at all.

    There have been a number of discussions of this type of thing, so you can search back a bit. I know there was an auto populating image gallery (I asked for it a while ago), and I will try to find that link for you. Then it's just a matter of integrating the uploads.

    You could also do a delete/admin page.

    I'd recommend adding a password to the pages as well, if nothing more than just a password field and using php-- <?php if ($_POST['password']!='mypasshere') die(); ?>, so you make it secure.


    As for images in particular, PHP has some functions for this. getimagesize() [look that up] will give you specific info about the image, but it's also the easiest way to check if a file is an image or not, when running through the directory.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    here you go try this... but If i were you should write your own so you understand it better....

    Code:
    <?php
    
      error_reporting(E_ALL ^ E_NOTICE); // Show all major errors.
    
      // Check to see if the button has been pressed
      if (!empty($_REQUEST['sendForm']))
      {
        // Assign the name to a variable
        $name = $_FILES['uploaded_file']['name'];
        // Assign the tmp_name to a variable
        $tmp_name = $_FILES['uploaded_file']['tmp_name'];
        // Assign the error to a variable
        $error = $_FILES['uploaded_file']['error'];
        // Assign the size to a variable
        $size = $_FILES['uploaded_file']['size'];
        // No trailing slash, folder where you want it uploaded too
        $uploadFilesTo = ' THE FOLDER ITS UPLOADED TO!! ';
        // Create safe filename
        $name = ereg_replace('[^A-Za-z0-9.]', '-', $name);
        // Disallowed file extensions
        $naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma", "mov", "js", "exe", "jsp", "map", "obj", "gif", " ", "", "html", "mp3", "mpu", "wav", "cur", "ani");
        // Returns an array that includes the extension
        $fileInfo = pathinfo($name);
        // Check extension
        if (!in_array($fileInfo['extension'], $naughtyFileExtension))
        {
          // Get filename
          $name = getNonExistingFilename($uploadFilesTo, $name);
          // Upload the file
          if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name))
          {
              // Show success message
              echo '<center><p>File uploaded to /'.$uploadFilesTo.'/'.$name.'</p></center><meta http-equiv="Refresh" content="0; URL=http://www.yoursite.com/folder thats its uploaded too">';
          }
          else
          {
              // Show failure message
              echo '<center><p>File failed to upload to /'.$name.'</p></center>';
          }
        }
        else
        {
            // Bad File type
            echo '<center><p>The file uses an extension we don\'t allow.</p></center>';
        }
      }
     
      // Functions do not need to be inline with the rest of the code
      function getNonExistingFilename($uploadFilesTo, $name)
      {
          if (!file_exists($uploadFilesTo . '/' . $name))
              return $name;
         
          return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name);
      }
    ?>
    <table bgcolor="gray" border="1"><tr>
    <tr><td>
    <form action="" method="post"    enctype="multipart/form-data">
      <input type="file" name="uploaded_file"><br>
      <input type="submit" name="sendForm" value="Upload Image">
    </form>
    
    </td></tr>
    </table>
    here is a upload script that does not use mysql all you have to do is find a way to have it populated or how ever you want.. but I think mysql might be the besy way to keep tract of things...
    Last edited by insanemonkey; 09-28-2007 at 05:16 AM.
    Hey new design new look, goto xudas for personal webdsign help.. (:

  4. #4
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    do you happen to know where i can find a full script that does this? So that i can look at it and see what it looks like. im very new to this stuff. thank you

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    or you can look on the php home site.
    http://www.php.net

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's a pretty complex script and you won't have trouble finding various parts (see the above post-- good [usable] examples at both sites) but a full script would be hard to find.
    Uploading is a "script" in itself in most cases. So would be listing the contents of a directory, etc. Don't take that to mean they can't be made into a single script, but it's just unlikely you'll find one put together exactly how you want it.

    The more complex a script gets the harder it is to create a multipurpose example. Take a look at some of the more complex image slideshows in the DD library. You'll see the code starts to get exponentially longer in the customizable ones to allow for user preference.
    That would be the same, but on a much larger scale, with such an upload script.

    It will fit your design and purposes better to just put it together yourself.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •