Drompo
11-03-2007, 08:33 PM
I see alot of people requesting these at the moment. So i'll post mine.
First make a folder called uploader.
Then make one called images in side your uploader file.
Make this file index.php
<?
// Script Made By Ashley Cusack
// CONFIG
$serverpath = "images/"; // Path to where images should be upload the server.
$urltoimages = "http://sitename.domain/uploader/images"; // Web address to where the images are accessible from.
$maxsize = "500000"; // Example - 20000 is the same as 20kb
$uniq = uniqid("");
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
echo "<br>Maximum File Size: $maxsizeb Bytes";
echo "<br>$file";
}
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><img src='$urltoimages/$name' border='0'>";
echo "<p>Direct Link: <input name='direct' type='text' size='75' value='$urltoimages/$name'></a></p>";
}
}
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>"; }
}
}
?>
Where is says
$urltoimages = "http://sitename.domain/uploader/images"; // Web address to where the images are accessible from.
Change it to where your 'images' folder is. (Do not leave a trailing slash)
Where is says
$maxsize = "500000"; // Example - 500000 is the same as 500kb
Change that to the maximum size you want in bytes.
That uploader will host nearly every type of image. But you can add things like zips if you like by adding
$allowedfiles[] = "zip";
$allowedfiles[] = "ZIP";
Below
$allowedfiles[] = "DIB";
Adn that concludes this tutorial.
First make a folder called uploader.
Then make one called images in side your uploader file.
Make this file index.php
<?
// Script Made By Ashley Cusack
// CONFIG
$serverpath = "images/"; // Path to where images should be upload the server.
$urltoimages = "http://sitename.domain/uploader/images"; // Web address to where the images are accessible from.
$maxsize = "500000"; // Example - 20000 is the same as 20kb
$uniq = uniqid("");
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='?mode=upload'>\n";
echo "Upload file: <input type='file' name='file'>\n";
echo "<br><input type='submit' name='Submit' value='Upload'>\n";
echo "<br>Maximum File Size: $maxsizeb Bytes";
echo "<br>$file";
}
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><img src='$urltoimages/$name' border='0'>";
echo "<p>Direct Link: <input name='direct' type='text' size='75' value='$urltoimages/$name'></a></p>";
}
}
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>"; }
}
}
?>
Where is says
$urltoimages = "http://sitename.domain/uploader/images"; // Web address to where the images are accessible from.
Change it to where your 'images' folder is. (Do not leave a trailing slash)
Where is says
$maxsize = "500000"; // Example - 500000 is the same as 500kb
Change that to the maximum size you want in bytes.
That uploader will host nearly every type of image. But you can add things like zips if you like by adding
$allowedfiles[] = "zip";
$allowedfiles[] = "ZIP";
Below
$allowedfiles[] = "DIB";
Adn that concludes this tutorial.