-
Uploader Script [TUT]
Right, some of you have requested a better version of my pervious script so here it is.
PHP Code:
<?
// Uploader Script made by E-Ash off Habbo UK
// CONFIG
$siteurl = "http://www."; //Must Include http:// and www. ending in where the images upload to with NO trailing slash
$serverpath = "images/"; // The End of the part above WITH trailing slash
$urltoimages = "$siteurl"; // Web address to where the images are accessible from.
$maxsize = "500000"; // Maximum size of the file people can upload
$uniq = uniqid("");
// CONFIG END
This is the start of your code. This is the configuration part.
$siteurl - eg. http://www.habboxforum.com/images (NO TRAILING SLASH)
$serverpath - eg. images/ (LEAVE TRAILING SLASH)
$maxsize - The maximum size that a file can be befor it is restricted.
PHP Code:
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='upload.php?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
$bytesize = "1000";
$kb = $maxsize/$bytesize;
echo "<br>Maximum File Size: $kb Kilobytes <em>($maxsize Bytes)</em>";
}
This Is the Form where you select the file to upload. This is self-explanatory.
PHP Code:
if ($mode == "upload") {
$file = $_FILES['file']['name'];
$name = time() . substr($file, -4);
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "jfef";
$allowedfiles[] = "jpe";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "JFEF";
$allowedfiles[] = "JPE";
$allowedfiles[] = "PNG";
$allowedfiles[] = "PDF";
$allowedfiles[] = "pdf";
$allowedfiles[] = "PSD";
$allowedfiles[] = "psd";
$allowedfiles[] = "bmp";
$allowedfiles[] = "BMP";
$allowedfiles[] = "tif";
$allowedfiles[] = "tiff";
$allowedfiles[] = "TIF";
$allowedfiles[] = "TIFF";
$allowedfiles[] = "dib";
$allowedfiles[] = "DIB";
This is the allowed files section. What ever files you want to allow to be uploaded just insert
PHP Code:
$allowedfiles[] = "EXTENTION";
In both upper and lower case letters
PHP Code:
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/" . $name;
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p>Please Note we do not take any responsibility of the images that you upload</p>";
?>
That is all the process stuff
HTML Code:
<!-- All the kinds of code you want to be outputed go here -->
<img src="<?php echo "$urltoimages/$name" ?>">
<br>Direct Link: <input name='direct' type='text' align='center' size='70' value='<?php echo "$urltoimages/$name" ?>'>
<br> BB Code:<input name='bbcode1' type='text' align='center' size='70' value='[img=<?php echo "$urltoimages/$name" ?>]'>
<br> BB Code: <input name='bbcode2' type='text' align='center' size='70' value='[img]<?php echo "$urltoimages/$name" ?>[/img]'>
<!-- End of all HTML Code -->
This is all the output code of the Direct links and BB codes.
You can add what ever you like as long its between the Hidden Text.
PHP Code:
<?php
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded becuase it is not a recognised image file. Please try again.</p>"; }
}
}
?>
And that is the error message if it hasn't been uploaded.
And thats now complete
Full Version below
__________________________________________________ _____________
PHP Code:
<?
// Script Made By Ashley Cusack
// CONFIG
$siteurl = "http://www."; //Must Include http:// and www. ending in where the images upload to with NO trailing slash
$serverpath = "images/"; // The End of the part above
$urltoimages = "$siteurl"; // Web address to where the images are accessible from.
$maxsize = "500000"; // Maximum size of the file people can upload
$uniq = uniqid("");
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='upload.php?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
$bytesize = "1000";
$kb = $maxsize/$bytesize;
echo "<br>Maximum File Size: $kb Kilobytes <em>($maxsize Bytes)</em>";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
$name = time() . substr($file, -4);
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "jfef";
$allowedfiles[] = "jpe";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "JFEF";
$allowedfiles[] = "JPE";
$allowedfiles[] = "PNG";
$allowedfiles[] = "PDF";
$allowedfiles[] = "pdf";
$allowedfiles[] = "PSD";
$allowedfiles[] = "psd";
$allowedfiles[] = "bmp";
$allowedfiles[] = "BMP";
$allowedfiles[] = "tif";
$allowedfiles[] = "tiff";
$allowedfiles[] = "TIF";
$allowedfiles[] = "TIFF";
$allowedfiles[] = "dib";
$allowedfiles[] = "DIB";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/" . $name;
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
echo "<p>Your image has been successfully uploaded to our server and can be accessed using the URL provided below.</p>";
echo "<p>Please Note we do not take any responsibility of the images that you upload</p>";
?>
<!-- All the kinds of code you want to be outputed go here -->
<img src="<?php echo "$urltoimages/$name" ?>">
<br>Direct Link: <input name='direct' type='text' align='center' size='70' value='<?php echo "$urltoimages/$name" ?>'>
<br> BB Code:<input name='bbcode1' type='text' align='center' size='70' value='[img=<?php echo "$urltoimages/$name" ?>]'>
<br> BB Code: <input name='bbcode2' type='text' align='center' size='70' value='[img]<?php echo "$urltoimages/$name" ?>[/img]'>
<!-- End of all HTML Code -->
<?php
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded becuase it is not a recognised image file. Please try again.</p>"; }
}
}
?>
-
-
-
His name is Ashely.
Nice tut.
-
Quote:
Originally Posted by
Invent
His name is Ashley.
Lol, yeah. Sorry about my post before, I'm tired.
-
Glad you like it, Hope this will come in useful for people
-
Correct me if im wrong, but you could upload bla.jpg.rar files and so on.
-
Nope as it looks at the last 3 letters of the file
-
wa
$siteurl - eg. http://www.habboxforum.com/images (NO TRAILING SLASH)
$serverpath - eg. images/ (LEAVE TRAILING SLASH)
wa u meen by NO TRAILInG Slash?
and leave trailing slash
and do u save the configuration file as config.php ?
-
No trailing slash means dont put a / on the end
leave trailing slash means put a / on the end, Dont bump this thread its a month old