Results 1 to 7 of 7

Thread: upload data to folder

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

    Default upload data to folder

    does anyone know if this is possible.ive searched a little but found nothing i wanted.
    what i would like is have a form that uploads to folder. lets call it the upload folder. then have it upload the link info into a database. so that i can just throw in $link; and it will display the links as if it is coming out of the db. any suggestions, comments?

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    There:

    PHP Code:
    <?php
    session_start
    ();
    if (isset(
    $_GET['file']))    {
        
    header('location:uploads/'.$_GET['file']);
    }
    /* //For debugging purposes
    if (file_exists('upload.phps')) { unlink('upload.phps'); }
    copy('upload.php','upload.phps');
    */
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Upload file</title>
    </head>

    <body>
    <?php
    //upload directory.
    //change to fit your need eg. files, upload .... etc.
    $upload_dir "uploads/";
    //number of files to upload.
    $num_files 1;
    //the file size in bytes.
    $size_bytes =2048000//51200 bytes = 50KB.
    //Extensions you want files uploaded limited to.
    $limitedext = array(".gif",".jpg",".jpeg",".png",".mov",".mpeg","mpg",".wmv",".wma",".bmp",".mp3");

    $error '';
    $missing=array();

    /* //For debugging purposes
    echo '<xmp>';
    print_r($_POST);
    echo '</xmp>';

    echo '<xmp>';
    print_r($_FILES);
    echo '</xmp>';
    */
    if (isset($_POST['Submit'])){
        echo 
    '<p>Uploading...</p>';
        
    flush();
        if (isset(
    $_POST['file_name']) &&
            isset(
    $_POST['name']) &&
            isset(
    $_POST['email']) &&
            isset(
    $_POST['filedescr']) &&
            isset(
    $_POST['name']) &&
            
    trim($_POST['file_name']) != '' &&
            
    trim($_POST['name']) != '' &&
            
    trim($_POST['email']) != '' &&
            
    trim($_POST['filedescr']) != '' &&
            
    trim($_POST['name']) != ''
            
    )    {
            
            
    $file $_FILES['file'];
            
    $filesize $file['size'];
            
    $tmp $file['tmp_name'];
            
    $ext strrchr($file['name'],'.');
            
    $name $_POST['file_name'].strtolower($ext);
            
            if (isset(
    $_SESSION['timer']) && time()-$_SESSION['timer'] < 30)    {
                echo 
    '<h2>Please wait another '.(30-(time()-$_SESSION['timer'])).' seconds before uploading again.</h2>';
            }
            elseif (!
    in_array(strtolower($ext),$limitedext)) {
                echo 
    '<h2>Sorry, you can only upload images, movies and music files.</h2>';
                
    uploadform();
            }
            elseif (
    $filesize $size_bytes)    {
                echo 
    '<h2>Sorry, the file you have chosen is too big.</h2>';
                
    uploadForm();
            }
            elseif (
    file_exists($upload_dir.$name))    {
                echo 
    '<p><strong>Warning: </strong>File already exists. Renaming...</p>';
                
    $arr_name explode('.',$name);
                unset(
    $arr_name[count($arr_name)-1]);
                
    $name $arr_name[0].'_'.$_POST['email'].$ext;
                if (
    move_uploaded_file($tmp,$upload_dir.$name))    {
                    echo 
    '<h2>Upload completed.</h2>';
                    echo 
    '<p>Your file has been uploaded. Click <a href="?">here</a> to return to the form.</p>';
                    
    //echo '<p>You can download the <a href="'.$_SERVER['PHP_SELF'].'?file='.urlencode($name).'>file here.</a></p>';
                    
    $_SESSION['timer'] = time();
                }
            }
            else    {
                if (
    move_uploaded_file($tmp,$upload_dir.$name))    {
                    echo 
    '<h2>Upload completed.</h2>';
                    echo 
    '<p>Your file has been uploaded. Click <a href="?">here</a> to return to the form.</p>';
                    
    //echo '<p>You can download the <a href="'.$_SERVER['PHP_SELF'].'?file='.urlencode($name).'>file here.</a></p>';
                    
    $_SESSION['timer'] = time();
                }
            }
        
    //    sleep(3);
        
    }
        else    {
            echo 
    '<h2>Fields Missing.</h2>';
            
    uploadForm();
        }
    }
    else    {
        
    uploadForm();
    }
    function 
    get($field)    {
        echo isset(
    $_POST[$field]) ? $_POST[$field] : '';
    }
    function 
    uploadForm()    {
        global 
    $error;
        if (
    $error != '')    {
            echo 
    '<h2>'.$error.'</h2>';
        }
    ?>
    <form name="uploader" action="" method="post" enctype="multipart/form-data">
        <p>
          <label>Name: <input type="text" name="name" value="<?php get('name'); ?>"></label>
        </p>
        <p>
          <label>E-Mail Address: <input type="text" name="email" value="<?php get('email'); ?>"></label>
        </p>
        <p>
          <label>File Description:<br><textarea name="filedescr" cols="50" rows="10"><?php get('filedescr'); ?></textarea></label>
        </p>
        <p>
          <label>File: <input type="file" name="file" value="<?php get('file'); ?>"></label>
        </p>
        <p>
          <label>File Name: <input type="text" name="file_name" value="<?php get('file_name'); ?>"></label>
        </p>
        <p>Maximum Size: 2MB</p>
        <p>
          <label><input type="submit" name="Submit" value="Upload!"></label>
        </p>
    </form>
    <?php ?>
    </body>
    </html>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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

    Default

    is it possible so that if someone uploads a movie file that it uploads to a "vids" folder rather then the default upload folder? and then also to have a page that automatically displays a player for each vid?

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    is it possible so that if someone uploads a movie file that it uploads to a "vids" folder rather then the default upload folder?
    PHP Code:
    ...
    //upload directory.
    //change to fit your need eg. files, upload .... etc.
    $upload_dir "uploads/";
    ... 
    As it said in the script, change it to fit your needs, aka. change uploads/ to vids/

    and then also to have a page that automatically displays a player for each vid?
    Have a look at the PHP directory functions on php.net
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

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

    Default

    Now how would i put the link into a database and then read the link from that database

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

    Default

    links are just a string of characters. so put the url to the link then in the processing after you grab the string you can decide what to do with it...

    meaning.

    TABLE links
    Code:
    id INT(5) NOT NULL AUTO-INCREMENT
    title VARCHAR(25) NOT NULL
    description VARCHAR(75)
    url VARCHAR(255) NOT NULL
    would set up a table with an auto-incrementing id field, a title which is displayed as what the user sees, a description that gets up into the "title" attribute of the link and a url which is the string location of the link. some data might look like

    Code:
    1     link     desc     /path/to/link
    2     Dynamic Drive     Dynamic Drive - Scripts and Help Forums     www.dynamicdrive.com/forums
    3     Google     Google Home     www.google.com
    that is very crude example but that is some sample input you could see to grab the info you would use your server-side language... PHP is this example
    PHP Code:
    <?php 
    $connection 
    mysql_connection('host','username','password');
    $conn select_mysql_db($connection'database');

    $query "SELECT title,description,url FROM links WHERE id='2'";
    if( 
    $conn && $res=mysql_query($query) )
    {
    ?>
         <ul>
    <?php
         
    while($rs=mysql_fetch_array($res))
         {
    ?>
              <li><a href="<?= $rs['url']; ?>" title="<?= $rs['description']; ?>"><?= $rs['title']; ?></a></li>
    <?php
         
    }
    ?>
         </ul>
    <?php
    }
    else
    {
          
    $error[] = "__ERROR_MESSAGE__";
    }
    ?>

  7. #7
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    For the 'vids upload' question, I would suggest that your uploads of all types go to one directory. Then from there, you can run tests on the file and decide where and if you want to save it, at the same time write to the database the file name, source, path to the file, file status, number of downloads, flags, category variables, etc. The file could be corrupted, could be virused or bogus, have the wrong extension, maybe even never ends..... (except with a timeout), etc. This gives you the ability to monitor or 'approve' the file for quality and content if you so need. Automatic script execution for movement and appending to a database can be set with crontab.
    Last edited by Strangeplant; 01-09-2008 at 07:42 PM. Reason: spelling

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
  •