Because finding a working, customizable image upload script is hard nowadays, I decided to make my own (Not the best upload script, but it works).
This is fully customizable, and you can easily make it so that it submits the images to a database allowing you to add "Recently uploaded" and a "Share Image" pages. If you need help with that bit, just reply and ill tell you what to add
All you have to do is removed "exit;" from line 11 just to show that you actually read this and change the domains to your domain (Remember to CHMOD your folder).
Credit to Invent for telling me how to use arrays.
Demo: www.v-habbo.com/upload
Download link: http://v-habbo.com/upload/imager.zip
upload.php
Post updated by ,Jess, (Forum Super Moderator): On request of user.PHP Code:<?php
$dir = "/home/vhabbo/public_html/images/uploads"; // This is the directory you wish your images to be uploaded. Change "vhabbo" to your username and remember to CHMOD to 777.
$maxsize = "10000000"; // This is the max file size
$types_alowed = array("gif", "png", "bmp", "jpg", "jpeg"); // These are the files alowed to upload
$websiteurl = ("v-habbo.com"); // Change this to your website URL, adding a www. is additional.
// Only edit below if you have knowledge in php.
if(isset($_FILES["file"])) {
$file = $_FILES["file"]["name"];
$dot = explode( ".", $file);
$tempname = $_FILES["file"]["tmp_name"];
$tmpname = $_FILES["file"]["tmp_name"];
$info = getimagesize( $tmpname );
$re1 = '(image)';
if ( $_FILES["file"]["size"] > $maxsize || $file == "" ) {
echo ( "<p>The following errors occured:<ul>" );
$end = "</ul></p>";
if($file == "") {
echo("<li>Please complete the required field \"File\".</li>");
$error2 = "1";
}
if($_FILES["file"]["size"] > $maxsize) {
echo("<li>The size of your image is too big.</li>");
}
}
else {
if ( preg_match( "/" . $re1 . "/is", image_type_to_mime_type( $info[2] ) ) ) {
$name = uniqid("img").$_FILES["file"]["name"]; // This will create a random name for the file
$newname = str_replace( " ", "_", $name); // This will replace any spaces in the file name
move_uploaded_file($tempname, "$dir/$newname");
echo("<img src=\"http://$websiteurl/images/uploads/$newname\" border=\"0\" />
<fieldset>
<legend>Direct Link:</legend>
<input type=\"text\" name=\"direct\" value=\"http://$websiteurl/images/uploads/$newname\" class=\"file\" size=\"100%\"><br>
</fieldset>
<legend>HTML Clode:</legend>
<input type=\"text\" name=\"direct\" value=\"<a href="http://www.$websiteurl/upload" target="_blank"><img src="http://$websiteurl/images/uploads/$newname" border="0"></a>\" class=\"file\" size=\"100%\"><br>
</fieldset>");
}
else {
echo ( "<p>The following errors occured:<ul>" );
$end = "</ul></p>";
echo("<li>You can only upload image files.</li></ul></p>");
echo("$end");
}
}
}
else {
?>
<form method="post" enctype="multipart/form-data">
<fieldset>
<legend>Select File:</legend>
<input type="file" name="file" class="file" size="20"><br>
</fieldset>
<br>
<input class="submit" type="submit" value="Upload" name="submit">
</form>
<?
}
?>






Reply With Quote
lol.





