Jump to content

  •  

  • iBotModz CBox


    Photo

    php Upload


    • Please log in to reply
    9 replies to this topic

    #1 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 19 August 2009 - 08:12 AM

    Guys, i need a php upload script, thats simple to use/install.

    It can upload any file size, i can manage extensions (some sort of .ini). And when uploaded it shows a link to the file.

    Thanks.

    #2 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 19 August 2009 - 06:19 PM

    upload.php
    <?php
       // Configuration
          $allowed_filetypes = array('.rar','.zip','.sppf','.ppf','.serenity','.txt', '.png','.jpg', '.bmp'); 
          $max_filesize = 1310720; 
          $upload_path = './files/'; 
    	  
       $filename = $_FILES['userfile']['name']; 
       $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
       
       if(!in_array($ext,$allowed_filetypes))
          die('The file you attempted to upload is not allowed.');
       
       if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
          die('The file you attempted to upload is too large, our limit is 10MB.');
     
       if(!is_writable($upload_path))
          die('You cannot upload to the specified directory, please CHMOD it to 777.');
     
       // Upload the file to your specified path.
       if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
             echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; 
          else
             echo 'There was an error during the file upload.  Please try again.'; // It failed <img src='http://www.ibotmodz.net/forum/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':(' />.
     
    ?>

    Page with upload (Like index.html)
    <form action="./upload.php" method="post" enctype="multipart/form-data">
    
    <label for="file"></label>
    <div align="center"><input name="userfile" id="file" type="file" /> <br />
    
    <button>Upload File</button>


    The most basic there is.

    #3 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 20 August 2009 - 01:37 PM

    Thanks so much babe :)

    #4 Dark Slipstream

    Dark Slipstream

      Blue Shadowz Owner

    • Members+

    • 2,829 posts
    • Joined: 19-April 08
    • Gender:Male
    • Location:Canada, ON

    Posted 21 August 2009 - 02:10 AM

    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);


    Simple question, but without actually testing this code, I beleive this will return anything from the first instance of a period to the end of the filename.


    Edit: Confirmed, yes it will. Simple fix, use strrpos instead of strpos.

    Edited by Dark Slipstream, 21 August 2009 - 02:16 AM.


    #5 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 21 August 2009 - 05:08 AM

    I've been using that exact script on iBotFiles forever and had no problems, so don't entirely know what the problem is.
    If its not broken, why fix it lol?

    #6 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 21 August 2009 - 08:51 AM

    Peaches you know iBotFiles.com loops after 5MB. You have to edit the php.ini file to allow http uploads over 5MB.

    Example:

    http://ibotmodz.rogue-mods.com/upload/

    Edited by Dakote, 21 August 2009 - 08:52 AM.


    #7 Dark Slipstream

    Dark Slipstream

      Blue Shadowz Owner

    • Members+

    • 2,829 posts
    • Joined: 19-April 08
    • Gender:Male
    • Location:Canada, ON

    Posted 21 August 2009 - 01:16 PM

    Well strpos returns the first occurrence of the period in the filename. strrpos returns the last occurrence. Basically, if I went to upload IP.Board3.psd, the file extension would be returned as .Board3.psd.

    #8 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 21 August 2009 - 02:18 PM

    No, it doesn't for me. i have uploaded 2 films, 2 albums and 5 apps, all of them came out as .rar.

    #9 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 21 August 2009 - 08:04 PM

    iBotFiles is my tiny upload area. I'm not going to mess with its source, it works the way it is and thats fine with me. My php.ini is maxed at 5MB of which my hoster limits, it just loops if larger because of a php timeout.

    #10 Rogue Modder

    Rogue Modder

      Class of 2008

    • VIP

    • 1,328 posts
    • Joined: 02-January 09
    • Gender:Male
    • Location:London, UK

    Posted 21 August 2009 - 09:25 PM

    Ahhh, thats annoying.