so your looking for a script that will just upload images or what not... why didnt you say that.. you don't use fopen and script like that for uploading...
welll here is a upload script... I like this one the most since it tells the person the link of the file is at....
PHP 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 = 'LOCATION TO YOUR UPLOADED FILES';
// Create safe filename
$name = ereg_replace('[^A-Za-z0-9.]', '-', $name);
// Disallowed file extensions
//what files you don't want upoad... leave this alone and you should be fine but you could add more
$naughtyFileExtension = array("php", "php3", "asp", "inc", "txt", "wma", "mov", "js", "exe", "jsp", "map", "obj", " ", "", "html", "mp3", "mpu", "wav", "cur", "ani"); // 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><p>File uploaded to http://www.yoursite.com/'.$uploadFilesTo.'/'.$name.'</p></center>';
}
else
{
// Show failure message
echo '<center><p>File failed to upload to /'.$name.'</p></center>';
}
}
else
{
// Bad File type
echo '<center><p>The file uses an extension we don\'t allow.</p></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);
}
?>
<table bgcolor="gray" border="1"><tr>
<tr><td>
<br>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploaded_file"><br>
<input type="submit" name="sendForm" value="Upload Image">
</form>
</td></tr>
</table>
now just fool around with the script.... but you have to edit some of the things though.. any question let me know
Bookmarks