uploading an image to a server

how a user can upload an image to my server, to a specific folder

Page 1 of 1

2 Replies - 1982 Views - Last Post: 28 February 2007 - 03:06 PM Rate Topic: -----

#1 psydoll   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 23-February 07

uploading an image to a server

Posted 27 February 2007 - 02:54 AM

I have set it up for jpeg files only right now. what im trying to get this code to do is allow the user to upload jpegs, gifs, bitmaps to a specific folder on my server called applicantsImages. I am thinking the most logical way to get jpegs as well as gifs and bitmaps would be to use cases as I saw in others code, but I am a little unsure how to change what i have which is if statements to cases. also im not sure how to designate the server folder they will end up in. Right now the site when run on the remote server keeps telling me: "Could not copy" , here is the php code i have created thus far:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="file" name="imagefile">
<br>
<input type="submit" name="Submit" value="Submit"> 
<?
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:

if ($_FILES['imagefile']['type'] == "image/jpeg"){ 
	copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) 
	or die ("Could not copy");
	echo ""; 
		echo "Name: ".$_FILES['imagefile']['name'].""; 
		echo "Size: ".$_FILES['imagefile']['size'].""; 
		echo "Type: ".$_FILES['imagefile']['type'].""; 
		echo "Copy Done...."; 
	  }
	  
	 else {
			echo "<br><br>";
			echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
		}
} 	
	?> </form> 
</body>
</html>


[mod edit]Use the code tags!

Is This A Good Question/Topic? 0
  • +

Replies To: uploading an image to a server

#2 snoj   User is offline

  • Married Life
  • member icon

Reputation: 93
  • View blog
  • Posts: 3,583
  • Joined: 31-March 03

Re: uploading an image to a server

Posted 27 February 2007 - 07:13 AM

First off you should change $Submit to $_POST['Submit'] as register globals is never a good way to code.

The problem is likely in that you don't have the proper permissions for the destination folder.
Was This Post Helpful? 0
  • +
  • -

#3 Xmod   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 19-January 07

Re: uploading an image to a server

Posted 28 February 2007 - 03:06 PM

look at this example

if(isset($_POST[s1]))
{
	if(!empty($_FILES[images][name][0]))
	{
		while(list($key,$value) = each($_FILES[images][name]))
		{
			if(!empty($value))
			{
				$NewImageName = $t."_offer_".$value;
				copy($_FILES[images][tmp_name][$key], "re_images/".$NewImageName);
				$MyImages[] = $NewImageName;
				//Below is the convertion of images if servers uses IMAGEMAGICK
				exec("convert re_images/$NewImageName -resize 460x400 -quality 65 -compress JPEG re_images/$NewImageName");
			}
		}	

		if(!empty($MyImages))
		{
			$ImageStr = implode("|", $MyImages);
		}

	}



this example is also using imagemagick to compress the image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1