Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Uploading System

  1. #1
    Join Date
    Jun 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Uploading System

    Hello Everyone,

    I was looking for a script where users can upload files to the website and it would store them maybe in the FTP or somewhere private where only the respective admin would have access to download it?

    like for example: www.yousendit.com you can upload files and you can decide whether you need to be a registered user to download your file or not. Would this be a HTML script? If not, what kind of script would I be looking for?

    Thanks for your help

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

    Default

    this could not be any type of client-side programming languages. you would need a server-side language such as (PHP/ASP) and some of database to store users / access codes.

  3. #3
    Join Date
    Jun 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by boogyman View Post
    (PHP/ASP) and some of database to store users / access codes.
    I run PHP off the website.

    As for the website, you need to have a login name to login into the website.


    Like I could have users attach files but I would have to set it private and all.

    So there is no easy way to do this? Only way possible is kind of like a forum where people can post attachments?

    Thanks

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

    Default

    okay so php is installed? how about a database? MySQL would probably be the easiest and its free.

    and no you do not have to set everything "private" and all. you can make the site viewable to the world or only to certain people to login, or what would be ideal is to offer a "level" type system where you have some services for free, and you have prioritized / enhanced services for people whom have an account, now whether that be a paid account or not is again up to you. Its not really a matter of how "easy" it is, its a matter of your experience and knowledge.

    If you do not have any experience working with this type of project, and you intend this to be a success and growing site, you probably would be better just using a model like phpBB which has a built in framework and offers all of the scripts you would need for this type of project... however if this is a developmental / educational site for you to learn how to do what you are asking it would probably take you a long time to write the scripts but yes its possible. Easy? probably not, but feasible nonetheless.

    it really just depends on what level of committment, your time to schedule for getting the site operational, your intentions for the site, etcetc...
    if you are building the site yourself there are numerous scripts on the web that will tell you how to write a file to your server, and check for some basic arguments and security concerns. do a quick search on google, and I also think Twey has something on his site that depicts something like this

  5. #5
    Join Date
    Jun 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by boogyman View Post
    okay so php is installed? how about a database? MySQL would probably be the easiest and its free.
    Yes, PHP is installed. (I use Drupal) And I use MySQL


    Quote Originally Posted by boogyman View Post
    If you do not have any experience working with this type of project, and you intend this to be a success and growing site, you probably would be better just using a model like phpBB which has a built in framework and offers all of the scripts you would need for this type of project... however if this is a developmental / educational site for you to learn how to do what you are asking it would probably take you a long time to write the scripts but yes its possible. Easy? probably not, but feasible nonetheless.

    it really just depends on what level of committment, your time to schedule for getting the site operational, your intentions for the site, etcetc...
    if you are building the site yourself there are numerous scripts on the web that will tell you how to write a file to your server, and check for some basic arguments and security concerns. do a quick search on google, and I also think Twey has something on his site that depicts something like this
    [/QUOTE]

    I appreciate the time you took to write this out and give me some ideas. I got some ideas from what you said and I will apply them and then come back and tell you guys the way I did it... incase someone has a similar question.

    Thanks
    Last edited by WebMaker12; 08-31-2007 at 07:57 PM.

  6. #6
    Join Date
    May 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here's a link to a tutorial I did once. It allows a user to upload something to a folder you create on your server. It worked for me... http://www.tizag.com/phpT/fileupload.php

  7. #7
    Join Date
    Jun 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Awesome!!

    Thanks a lot

    Here is what i've done so far.






    (That is the basic part)

    But here is where I am lost:


    // Where the file is going to be placed
    $target_path = "uploads/";

    /* Add the original filename to our target path.
    Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    $_FILES['uploadedfile']['tmp_name'];


    Lets say I want the files to be stored in: http://www.biblical-education.com/upload/files and from there I can open that file in my FTP and am able to see the uploaded files.

    Where do I add that part of the line? Would I replace it with the "uploads/filename.extension"?

    Also

    $target_path = "uploads/";

    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }

    I understand the last line for the error... but the if statement confuses me -- What would I need to change here?

    Sorry for the confusion I might of caused.

    Thanks
    Last edited by WebMaker12; 08-31-2007 at 08:11 PM.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    But here is where I am lost:

    Code:
    // Where the file is going to be placed
    $target_path = "uploads/";
    
    /* Add the original filename to our target path.
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    Lets say I want the files to be stored in: http://www.biblical-education.com/upload/files and from there I can open that file in my FTP and am able to see the uploaded files.

    Where do I add that part of the line?

    You would change this:

    Code:
    // Where the file is going to be placed
    $target_path = "uploads/";
    to point to the directory in which you want users to upload to. So in this case, it would be:

    Code:
    $target_path = 'upload/files/';

    Code:
    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }
    ... the if statement confuses me -- What would I need to change here?
    You do not need to change anything here. The if statement basically says that if the uploaded file is uploaded (or has been moved from a temporary place to the final destination), to continue and show that the file has infact been uploaded. Otherwise, display the error.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Jun 2007
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Got it working!!!


    Thanks a lot for your help guys.

    keep up the good work here

  10. #10
    Join Date
    Jan 2007
    Location
    The stage
    Posts
    568
    Thanks
    23
    Thanked 6 Times in 6 Posts

    Default

    Ok I found this great code man I think it fits most your needs, besides it validates itself by checking file type, size, and you can even upload more than 1 file...
    Heres the PHP code
    Code:
    <?php//upload directory.
    //change to fit your need eg. files, upload .... etc.
    $upload_dir = "images/";
    //number of files to upload.
    $num_files = 5;
    //the file size in bytes.
    $size_bytes =51200; //51200 bytes = 50KB.
    //1024 divided by bytes gets you KB
    //Extensions you want files uploaded limited to.
    $limitedext = array(".gif",".jpg",".jpeg",".png",".txt",".nfo",".doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".exe");
    
    
       //check if the directory exists or not.
       if (!is_dir("$upload_dir")) {
          die ("Error: The directory <b>($upload_dir)</b> doesn't exist");
       }
       //check if the directory is writable.
       if (!is_writeable("$upload_dir")){
          die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)");
       }
    
    
    //if the form has been submitted, then do the upload process
    //infact, if you clicked on (Upload Now!) button.
    if (isset($_POST['upload_form'])){
    
           echo "<h3>Upload results:</h3>";
    
           //do a loop for uploading files based on ($num_files) number of files.
           for ($i = 1; $i <= $num_files; $i++) {
    
               //define variables to hold the values.
               $new_file = $_FILES['file'.$i];
               $file_name = $new_file['name'];
               //to remove spaces from file name we have to replace it with "_".
               $file_name = str_replace(' ', '_', $file_name);
               $file_tmp = $new_file['tmp_name'];
               $file_size = $new_file['size'];
    
               #-----------------------------------------------------------#
               # this code will check if the files was selected or not.    #
               #-----------------------------------------------------------#
    
               if (!is_uploaded_file($file_tmp)) {
                  //print error message and file number.
                  echo "File $i: Not selected.<br>";
               }else{
                     #-----------------------------------------------------------#
                     # this code will check file extension                       #
                     #-----------------------------------------------------------#
    
                     $ext = strrchr($file_name,'.');
                     if (!in_array(strtolower($ext),$limitedext)) {
                        echo "File $i: ($file_name) Wrong file extension. <br>";
                     }else{
                           #-----------------------------------------------------------#
                           # this code will check file size is correct                 #
                           #-----------------------------------------------------------#
    
                           if ($file_size > $size_bytes){
                               echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
                           }else{
                                 #-----------------------------------------------------------#
                                 # this code check if file is Already EXISTS.                #
                                 #-----------------------------------------------------------#
    
                                 if(file_exists($upload_dir.$file_name)){
                                     echo "File $i: ($file_name) already exists.<br>";
                                 }else{
                                       #-----------------------------------------------------------#
                                       # this function will upload the files.  :) ;) cool          #
                                       #-----------------------------------------------------------#
                                       if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
                                           echo "File $i: ($file_name) Uploaded.<br>";
                                       }else{
                                            echo "File $i: Faild to upload.<br>";
                                       }#end of (move_uploaded_file).
    
                                 }#end of (file_exists).
    
                           }#end of (file_size).
    
                     }#end of (limitedext).
    
               }#end of (!is_uploaded_file).
    
           }#end of (for loop).
           # print back button.
           echo "&#187;<a href=\"$_SERVER[PHP_SELF]\">back</a>";
    ////////////////////////////////////////////////////////////////////////////////
    //else if the form didn't submitted then show it.
    }else{
        echo " <h3>Select files to upload!.</h3>
               Max file size = ". $size_bytes / 1024 ." KB";
        echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
               // show the file input field based on($num_files).
               for ($i = 1; $i <= $num_files; $i++) {
                   echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
               }
        echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
               <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
               </form>";
    }
    
    ?>
    Hopefully it works for you...
    Note I got it off PHPFREAKS.com

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
  •