PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Advanced Image Uploader
Your Ad Here

Advanced Image Uploader


Advanced Image UploaderThis is an advanced image uploader...

1. Make this a file called "imageupload.php

<form enctype="multipart/form-data" action="imageupload.php" method="post">
Select Image: <input type="file" name="userfile">
<input type="submit" value="Upload!">
</form>

<?php

$path = "images/";     //Folder where uploaded files go
$max_size = "200000";  // Max size for uploaded files

$filename = $_POST['userfile'];

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { 
echo "The File is Too Big. The Max File Size is $max_size KB<br>n"; 
exit; 
}

if (
   ($HTTP_POST_FILES['userfile']['type']=="image/gif")   ||         
   ($HTTP_POST_FILES['userfile']['type']=="image/jpg")   ||  
   ($HTTP_POST_FILES['userfile']['type']=="image/bmp")   ||
   ($HTTP_POST_FILES['userfile']['type']=="image/png")   ||
   ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")
)
{

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) 

echo "A File With That Name Already Exists!<br>"; 
exit; 
}

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .

$HTTP_POST_FILES['userfile']['name']);
if (!$res){ 
echo "Upload Failed!<br>"; 
exit; 

else{ 
echo "Upload Sucessful!<br>"; 
}

echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>";
echo "<a href=$path".$HTTP_POST_FILES['userfile']['name'].">View Image</a>";

else 
{
echo "Wrong File Type<br>"; 
exit; 
}
}

?>

Read the two comments in the file.



Author's URL: Spacetech
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Advanced Image Uploader"

Only registered users can write comment

Reader's comments