<?php
// Create the main upload function
function do_upload() {
// Create an array containing all valid upload file types for this script
$allowed_types = array(
"image/gif" => "gif",
"image/pjpeg" => "jpg",
"image/jpg" => "jpg",
"image/jpeg" => "jpg",
// Add more types here if you like
);
// Check to see if the file type is in the allowed types array
if(!array_key_exists($_FILES['userfile']['type'], $allowed_types)) {
die("Invalid file type.");
}
// Set the maximum uploadable file size => 512000 = 500kb
$maxfilesize = 512000;
// Is the file larger than it is allowed to be?
if($_FILES['userfile']['size'] > $maxfilesize) {
die("File too large");
}
// Where will the file be uploaded to?
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/may/";
// What is the files temporary name?
$file = $_FILES['userfile']['tmp_name'];
// What is the files actual name?
$filename = $_FILES['userfile']['name'];
// Does this file already exist on the server?
if(file_exists($uploaddir . $filename))
{
//die("A file with that name already exists on this server.");
die("File already existed, [img]http://www.mysite.net/may/" . $filename ."[/img]");
} else {
// This file does not already exist, so copy it.
copy($file, $uploaddir.$filename) or die("Could not copy file.");
}
// All done! :-)
echo "Upload successful";
echo "<br />";
echo "<br />";
echo "Copy and Paste the following Code";
echo "<br/>";
echo "<font color=green><b>";
echo "<br />";
echo "[img]http://www.mysite.net/may/";
echo $filename;
echo "[/img]";
echo "<br/>";
echo "<br/>";
echo '<img src="may/'.$filename.'">';
echo "<br />";
echo "<br />";
echo "</font>";
}
?>
<html>
<head>
<link href="sponge.css" rel="stylesheet" type="text/css">
<title>mysite Image Upload</title>
</head>
<body bgcolor="#dddddd">
<center>
<img src="images/weblogo.gif">
<table border="0"><tr><td class="cellhead">mysite Image uploader 2006, Please dont abuse..</td></tr>
<tr><td class="cellcontent2"><br /><br />Webmasters, this site is hotlinked, this uploader is for mysite forum members only, the links will not work elsewhere.</td></tr></table>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="action" value="do_upload">
<input type="file" name="userfile"><br />
<input type="submit" name="submit" value="Upload Image">
</form>
</body>
</html>
<?php
// If the form has been completed, execute the upload function (above).
if($_POST['action'] == "do_upload") {
do_upload();
}
?>