User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,379 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,008 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1052 | Replies: 2
Reply
Join Date: May 2008
Posts: 1
Reputation: ChristieLuv is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ChristieLuv ChristieLuv is offline Offline
Newbie Poster

An Upload and Image Display code?

  #1  
May 14th, 2008
Hi! I'm trying to find a basic PHP code that uses an HTML form to upload an image to a specified directory and after that the image address can be called for displaying the image with PHP or putting it in a textarea box for linking. I know it seems simple but I've been looking everywhere for one. I must be looking in the wrong places. If anyone can give any help I would so appreciate it!

Thank you!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 298
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: An Upload and Image Display code?

  #2  
May 15th, 2008
$image=$_FILES['broad1_image']['name'];
 	// if it is not empty
 	if ($image) 
 	{
 		// get the original name of the file from the clients machine
 		$filename = stripslashes($_FILES['broad1_image']['name']);
 		
 		// get the extension of the file in a lower case format
 	 	$extension = getExtension($filename);
 		$extension = strtolower($extension);
 		// if it is not a known extension, we will suppose it is an error, print an error message 
 		//and will not upload the file, otherwise we continue
 		if (($extension != "jpg")  && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))	
 		{
 			echo '<h1>Unknown extension!</h1>';
 			$errors=1;
 		}
 		else
 		{
 			// get the size of the image in bytes
 			// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which 
			//the uploaded file was stored on the server
 			$size=getimagesize($_FILES['broad1_image']['tmp_name']);
 			$sizekb=filesize($_FILES['broad1_image']['tmp_name']);

 			//compare the size with the maxim size we defined and print error if bigger
 			if ($sizekb > MAX_SIZE*1024)
 			{
 				echo '<h1>You have exceeded the size limit!</h1>';
 				$errors=1;
 			}


  			//we will give an unique name, for example the time in unix time format
 			$image_name=image1.'.'.$extension;
 			//the new name will be containing the full path where will be stored change these to the file where you would like to store the images.  (images folder)
 		 	$broad1name="image/".$image_name;
 		 	$broad1name2="image/thumbs/thumb_".$image_name . $rand;
 			$copied = copy($_FILES['broad1_image']['tmp_name'], $broad1name);
 			$copied = copy($_FILES['broad1_image']['tmp_name'], $broad1name2);
 			//we verify if the image has been uploaded, and print error instead
 			if (!$copied) {
 				echo '<h1>Copy unsuccessfull!</h1>';
 				$errors=1;
 			}
 			else
 			{
 				// the new thumbnail image will be placed in images/thumbs/ folder
 				$thumb_name=$broad1name2;
 				// call the function that will create the thumbnail. The function will get as parameters 
 				//the image name, the thumbnail name and the width and height desired for the thumbnail
 				$thumb=make_thumb($broad1name,$thumb_name,WIDTH,HEIGHT);
 			}
 		}	
 	}
 }
			
  //If no errors registred, print the success message and show the thumbnail image created
 if(isset($_POST['Submit']) && !$errors) 
 {
 	echo "<h5>Thumbnail created Successfully!</h5>";
 	echo '<img src="'.$thumb_name.'">';
 } 

 ?> 
</p>
 	<form name="newad" method="post" enctype="multipart/form-data"  action="">
		<input type="file" name="broad1_image"  >
		<input name="Submit" type="submit" id="image1" value="Upload image" >
	
</form>

that should do the job for you. i am using this on a website i am building
Last edited by kevin wood : May 15th, 2008 at 5:18 am.
Reply With Quote  
Join Date: May 2008
Posts: 32
Reputation: servis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
servis servis is offline Offline
Light Poster

Re: An Upload and Image Display code?

  #3  
May 15th, 2008
if you are requiring a complete well documented and very much easy tutorial then follow the link www.php-mysql-tutorial.com. where everything about image upload is discussed in image gallery link..and plz let us confirm....whether it is enough???
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC