iBotModz CBox
php Upload
Started by Rogue Modder, Aug 19 2009 08:12 AM
9 replies to this topic
#2
Posted 19 August 2009 - 06:19 PM
upload.php
Page with upload (Like index.html)
The most basic there is.
<?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
Posted 20 August 2009 - 01:37 PM
Thanks so much babe
#4
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
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?
If its not broken, why fix it lol?
#6
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/
Example:
http://ibotmodz.rogue-mods.com/upload/
Edited by Dakote, 21 August 2009 - 08:52 AM.
#7
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
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
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
Posted 21 August 2009 - 09:25 PM
Ahhh, thats annoying.