Return to Snippet

Revision: 27883
at June 25, 2010 19:39 by jackoder

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


# Variables
$path = "images/";  
$max_size = "200000"; 

# File
$filename = $_POST['userfile']; 

# Control
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";  

# Type Control
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")   || 

# If File Exist
if (file_exists($path . $HTTP_POST_FILES['userfile']['name']))  
echo "A File With That Name Already Exists!<br>";  

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

if (!$res){  
echo "Upload Failed!<br>";  
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>"; 
echo "Wrong File Type<br>";  


Initial URL

Initial Description
You can use this script in your projects when you need an image upload function. It checks file type, file size and error report. I also want you to check [giochi di spongebob]( and [gratis mahjong]( too. I hope you will like this code line. 

Have a nice work.

Best wishes.

Initial Title
Image Upload with Php

Initial Tags
php, image, function

Initial Language