here you go, try this out..
Code:
<?php
error_reporting(E_ALL ^ E_NOTICE); // Show all major errors.
// Check to see if the button has been pressed
if (!empty($_REQUEST['sendForm']))
{
// Assign the name to a variable
$name = $_FILES['uploaded_file']['name'];
// Assign the tmp_name to a variable
$tmp_name = $_FILES['uploaded_file']['tmp_name'];
// Assign the error to a variable
$error = $_FILES['uploaded_file']['error'];
// Assign the size to a variable
$size = $_FILES['uploaded_file']['size'];
// No trailing slash
$uploadFilesTo = 'imgs';
// Create safe filename
$name = ereg_replace('[^A-Za-z0-9.]', '-', $name);
// Disallowed file extensions
$naughtyFileExtension = array("php2", "php3", "php4", "php5", "asp", "inc", "txt", "wma", "mov", "js", "exe", "jsp", "map", "obj", " ", "", "html", "mp3", "mpu", "wav", "cur", "ani", "fla", "swf");
// Returns an array that includes the extension
$fileInfo = pathinfo($name);
// Check extension
if (!in_array($fileInfo['extension'], $naughtyFileExtension))
{
// Get filename
$name = getNonExistingFilename($uploadFilesTo, $name);
// Upload the file
if (move_uploaded_file($tmp_name, $uploadFilesTo.'/'.$name))
{
// Show success message
echo '<center><a href="http://www.xudas.com/forum/imgupload/'.$uploadFilesTo.'/'.$name.'" target="_blank">
<img src="http://www.xudas.com/forum/imgupload/'.$uploadFilesTo.'/'.$name.'" align="top" width="100" border="0"></a>
<textarea>http://www.xudas.com/forum/imgupload/'.$uploadFilesTo.'/'.$name.'</textarea></center>';
}
else
{
// Show failure message
echo '<center><SPAN style="color:gray">File failed to upload to /'.$name.'</span></center>';
}
}
else
{
// Bad File type
echo '<center><SPAN style="color:gray">The file uses an extension we don\'t allow.</span></center>';
}
}
// Functions do not need to be inline with the rest of the code
function getNonExistingFilename($uploadFilesTo, $name)
{
if (!file_exists($uploadFilesTo . '/' . $name))
return $name;
return getNonExistingFilename($uploadFilesTo, rand(100, 200) . '_' . $name);
}
?>
<BR>
<center>
<table bgcolor="#000000" border="0" width="100%">
<tr><td>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file">
<input type="submit" name="sendForm" value="Upload">
</form>
</td></tr>
</table>
</center>
Bookmarks