Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts

    Uploader for newbie coders. Commented.

    Hey people, thought this might be useful. Its a veeeery easy way to upload things.
    The php

    PHP Code:
    <?php

    $max_size 
    15//Your maximum file size(in mb);
    $direc_copy "uploads/"//Directory to copy to
    //Seperate with a comma
    $accepted_file_list "video,image"// the files types you will allow to be copied, Possible options are:
    //text,image,audio,video,application

    $accepted_file_list explode(",",$accepted_file_list);
    $max_size = (($max_size 1024) * 1024);
    $submit $_POST['submit']; // get the submit
    if (isset($submit)){
           
    $filename $_FILES['file_upload']; //get the file details
        
    $mime_type explode("/"$filename['type']); //get the first bit of the mime type
         
    if (($filename['size'] > 0) and ($filename['size'] < $max_size)){ //check if a file actually exists.
            
    if (in_array($mime_type[0], $accepted_file_list)){//check if the file is in the accepted_file_list array
                
    copy($filename['tmp_name'], $direc_copy $filename['name']); // copy the file
                
    $message "Your file has been uploaded."//message if copied
                

                else {
                    
    $message "Filetype not supported"//message if filetype not supported
                    
    }
            } else {
                
    $message "File is outside of the allowed boundaries";
                }
    }
    ?>
    <form action="uploader_test.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">
    <input type="file" name="file_upload" id="file_upload">
    <input type="submit" name="submit" value="submit">
    </form>
    PHP Code:
    <?php echo($message "<br>" "The link is " $direc_copy $filename['name']); ?>

  2. Users who have thanked idalatob for this post:

    Bhodio (09-14-2007)

  • #2
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thats a nice simple script

  • #3
    afe
    afe is offline
    Banned
    Join Date
    Sep 2007
    Posts
    146
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Hey, I published a page for the uploader. http://www.athletes4excellence.com/uploader.php how come it takes me to a broken page after uploading?

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by afe View Post
    Hey, I published a page for the uploader. http://www.athletes4excellence.com/uploader.php how come it takes me to a broken page after uploading?
    the script is supposed to be put in a file called uploader_test.php u've put it in uploader.php but haven't changed the form-action

    Code:
    <form action="uploader.php" method="post" enctype="multipart/form-data" name="fileuploader" id="fileuploader">
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    afe
    afe is offline
    Banned
    Join Date
    Sep 2007
    Posts
    146
    Thanks
    43
    Thanked 0 Times in 0 Posts
    Ohh I see.
    thanks

    However, this is what I get now after clicking "Submit"

    "Warning: copy(uploads/1J4V6SCAF8V6FVCAAHPYS1CA38NA1KCAOEJJIQCA3OQUQVCA601F3ZCAE8MUBYCAC2KLK8CAHVUAECCAS0I322CAMAMTOBCA116R EPCAG7HN5CCACXACTOCA48F6VMCAF6A91UCAH7DNLGCATV3O53CACDBHIS.jpg) [function.copy]: failed to open stream: No such file or directory in /home/athletes/public_html/uploader.php on line 17"
    Last edited by afe; 12-02-2007 at 07:42 PM.

  • #6
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    create a folder called uploads

  • #7
    Senior Coder ahallicks's Avatar
    Join Date
    May 2006
    Location
    Lancaster, UK
    Posts
    1,134
    Thanks
    1
    Thanked 57 Times in 55 Posts
    Or, to be more specific (and the only way to get it to work on my server) change the upload path to:

    PHP Code:
    $direc_copy "/home/athletes/public_html/uploads/" //Directory to copy to 
    and create a folder called 'uploads' in the public_html folder of your server
    Last edited by ahallicks; 12-03-2007 at 12:28 PM.
    "write it for FireFox then hack it for IE."
    Quote Originally Posted by Mhtml View Post
    Domains are like women - all the good ones are taken unless you want one from some foreign country.
    Reputation is your friend

    Development & SEO Tools

  • #8
    Regular Coder
    Join Date
    Jan 2011
    Posts
    120
    Thanks
    6
    Thanked 2 Times in 2 Posts
    it's telling me the file is too large?...and i'm uploading a 26 kb pic.. does anyone know why?

  • #9
    p@p
    p@p is offline
    New Coder
    Join Date
    Apr 2010
    Location
    Indonesia
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MattClark View Post
    it's telling me the file is too large?...and i'm uploading a 26 kb pic.. does anyone know why?
    Did you already check the php.ini for maximum_uploads values?

  • #10
    New Coder
    Join Date
    May 2012
    Posts
    31
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Doesnt this essentially use a slightly modified version of the $_POST['submit'] bug as listed by TangoForce?

    if so a fix would be to change $submit to

    PHP Code:
     $submit $_POST['upload']; // get the submit 
    and add

    Code:
    <input type="hidden" name="upload" />

  • Users who have thanked Nikey646 for this post:

    WolfShade (05-11-2012)


  •  

    Posting Permissions

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