====== A simple, minimalist, personal file/image hosting script ====== ===== Presentation ===== I'm tired of image hosting services. Sites like //imageshack.us// are riddled with advertising. Sites like //imgur.com// delete images with no warning (Yes, it has happened to me several times). And some of them even want to sign-up for "premium" accounts ? WTF ? I decided to create my own, minimalist image hosting script for my own website. In fact, this script can be used to upload & host any kind of file. This is very simple. * Only you can upload files (using the password) * Anybody can see the images or download the files. ===== Instructions ===== - Save the following script as ''upload.php''. - Change the password (''$PASSWORD='toto';'') - Put the file in the root of your website. - Enjoy ! Files will be saved in the ''files'' subdirectory. You can change the directory name in the source (''$SUBDIR='files'''). ===== Source ===== '); fclose($h); } $scriptname = basename($_SERVER["SCRIPT_NAME"]); if (isset($_FILES['filetoupload']) && isset($_POST['password'])) { sleep(3); // Reduce brute-force attack effectiveness. if ($_POST['password']!=$PASSWORD) { print 'Wrong password.'; exit(); } $filename = $SUBDIR.'/'.basename( $_FILES['filetoupload']['name']); if (file_exists($filename)) { print 'This file already exists.'; exit(); } if(move_uploaded_file($_FILES['filetoupload']['tmp_name'], $filename)) { $serverport=''; if ($_SERVER["SERVER_PORT"]!='80') { $serverport=':'.$_SERVER["SERVER_PORT"]; } $fileurl='http://'.$_SERVER["SERVER_NAME"].$serverport.dirname($_SERVER["SCRIPT_NAME"]).'/'.$SUBDIR.'/'.basename($_FILES['filetoupload']['name']); echo 'The file/image was uploaded to '.$fileurl.''; } else { echo "There was an error uploading the file, please try again !"; } echo '

Upload another file.'; exit(); } print << File/image to upload:
Password:
Self-hosting php script by sebsauvage.net EOD; ?>
Please note that you are limited by the php upload file size limit (see php.ini) and the maximum POST size accepted by Apache (see you apache configuration). You can use ''phpinfo()'' to find this limit (Search for ''post_max_size'' and ''upload_max_filesize''). ===== Version history ===== * 0.1 : First version. * 0.2 : Moved php script out of the data directory. Added proper htaccess file for better security (prevent execution of uploaded files such as .php). * 0.3 : Accessing the data directory now redirects to the upload script. * 0.4 : Added a sleep() to reduce brute-force attack effectiveness. * 0.5 : Path correction (thanks to Elouan Pignet) ===== Screenshot ===== {{ :php:filehosting_1.png }} {{ :php:filehosting_2.png }} ~~DISCUSSION:closed~~