Jump to content


Image Uploader


3 replies to this topic

#1 Trix06

    Young Padawan

  • Members
  • Pip
  • 292 posts
  • Gender:Male
  • Location:NSW Australia
  • Interests:Web Design & Development, Graphic Design, Programming, Networking, Girls, The Beach, Amatuer Radio Communications and more.

Posted 12 October 2006 - 06:42 AM

G'day All,

I have been working on an image upload which will become a part of my portfolio. I get this error:

Fatal error: Call to undefined function exif_imagetype() in C:\Program Files\wamp\www\biz\new_client_added.php on line 99

I'm using these 2 pages:

new_client_added.php


<!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>JS Web Design v2.0 </title>
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body onload="MM_preloadImages('images/bttn_home_on.jpg','images/bttn_aboutus_on.jpg','images/bttn_portfolio_on.jpg','images/bttn_contactus_on.jpg','images/footer_on.jpg')">
<a name="top" id="top"></a>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
	<td><img src="images/header.jpg" width="800" height="150" /></td>
  </tr>
  <tr>
	<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td><img src="images/logo.jpg" width="290" height="100" /></td>
		<td><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/bttn_home_on.jpg',1)"><img src="images/bttn_home.jpg" alt="Home" name="home" width="135" height="100" border="0" id="home" /></a></td>
		<td><a href="about.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('about us','','images/bttn_aboutus_on.jpg',1)"><img src="images/bttn_aboutus.jpg" alt="About Us" name="about us" width="95" height="100" border="0" id="about us" /></a></td>
		<td><a href="portfolio.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Portfolio','','images/bttn_portfolio_on.jpg',1)"><img src="images/bttn_portfolio.jpg" alt="Portfolio" name="Portfolio" width="90" height="100" border="0" id="Portfolio" /></a></td>
		<td><a href="contact.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Contact Us','','images/bttn_contactus_on.jpg',1)"><img src="images/bttn_contactus.jpg" alt="Contact Us" name="Contact Us" width="190" height="100" border="0" id="Contact Us" /></a></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td class="bg-slice"><table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="left" valign="top" class="text"><p>Add A Client </p>
		  <?php
include ("config.php");

$result = "INSERT INTO clients (site, description, url) VALUES ('$_POST[site]','$_POST[description]','$_POST[url]')";

if (!mysql_query($result))
  {
  die('Error: ' . mysql_error());
  }
echo "Client Added!";

	  // include a trailing '/'
	  $directory_to_upload = "images/thumbnails";
	  // in bytes, this is 10kb
	  $max_file_size = 10240;
	  // max image width, in pixels
	  $max_width = 80;
	  // max image height, in pixels
	  $max_height = 80; 

$time = time();
$img_name = mysql_real_escape_string($_POST['image_name']);
$image_dimensions = getimagesize($_FILES['image_to_upload']['tmp_name']);
$image_height = $image_dimensions[1];
$image_width = $image_dimensions[0];
$errors = array();
if(empty($img_name) || empty($image_dimensions))
{
$errors[] = 'You did not enter an image name.';
}
if(empty($_FILES['image_to_upload']['name']))
{
$errors[] = 'You did not give a file to upload.';
}
if(!is_uploaded_file($_FILES['image_to_upload']['tmp_name']))
{
$errors[] = 'Error while uploading file.';
}
if($_FILES['image_to_upload']['size'] > $max_file_size)
{
$errors[] = 'Your image size was too big. The max is <b>' . $max_file_size . '</b> bytes.';
}
// check the image type, gif or jpg/jpeg is allowed
if(!exif_imagetype($_FILES['image_to_upload']['tmp_name']) == IMAGETYPE_GIF || !exif_imagetype($_FILES['image_to_upload']['tmp_name']) == IMAGETYPE_JPEG)
{
$errors[] = 'Your image must be a JPEG or a GIF.';
}
// check the iamge dimensions
if($image_height > $max_width)
{
$errors[] = 'Your image height was too big.';
}
if($image_width > $max_width)
{
$errors[] = 'Your image width was too large.';
}
if(count($errors) > 0)
{
echo '<b>ERRORS:</b><br />';
foreach($errors as $err)
{
echo $err . '<br />';
}
}
else
{
$image_url = $directory_to_upload . $time . '_' . $_FILES['image_to_upload']['name'];
if(copy($_FILES['image_to_upload']['tmp_name'], $image_url))
{
mysql_query("INSERT INTO clients (image_name, image_url) VALUES ('$img_name', '$image_url')");
echo 'Image uploaded successfully. <a href="' . $image_url . '">Click here to view your image</a>.';
}
else
{
echo 'The image upload process did not complete.';
}
}
?>
		  <p>&nbsp; </p></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><a href="#top" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Footer','','images/footer_on.jpg',1)"><img src="images/footer.jpg" name="Footer" width="800" height="65" border="0" id="Footer" /></a></td>
  </tr>
</table>
</body>
</html>

add_client.php
<!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>JS Web Design v2.0 </title>
<script type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>

<body onload="MM_preloadImages('images/bttn_home_on.jpg','images/bttn_aboutus_on.jpg','images/bttn_portfolio_on.jpg','images/bttn_contactus_on.jpg','images/footer_on.jpg')">
<a name="top" id="top"></a>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
	<td><img src="images/header.jpg" width="800" height="150" /></td>
  </tr>
  <tr>
	<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td><img src="images/logo.jpg" width="290" height="100" /></td>
		<td><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/bttn_home_on.jpg',1)"><img src="images/bttn_home.jpg" alt="Home" name="home" width="135" height="100" border="0" id="home" /></a></td>
		<td><a href="about.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('about us','','images/bttn_aboutus_on.jpg',1)"><img src="images/bttn_aboutus.jpg" alt="About Us" name="about us" width="95" height="100" border="0" id="about us" /></a></td>
		<td><a href="portfolio.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Portfolio','','images/bttn_portfolio_on.jpg',1)"><img src="images/bttn_portfolio.jpg" alt="Portfolio" name="Portfolio" width="90" height="100" border="0" id="Portfolio" /></a></td>
		<td><a href="contact.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Contact Us','','images/bttn_contactus_on.jpg',1)"><img src="images/bttn_contactus.jpg" alt="Contact Us" name="Contact Us" width="190" height="100" border="0" id="Contact Us" /></a></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td class="bg-slice"><table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td align="left" valign="top" class="text"><p>Add A Client </p>
		  <?php
include ("config.php");

$result = "INSERT INTO clients (site, description, url) VALUES ('$_POST[site]','$_POST[description]','$_POST[url]')";

if (!mysql_query($result))
  {
  die('Error: ' . mysql_error());
  }
echo "Client Added!";
?>
		  <form id="add_client" name="add_client" method="post" action="new_client_added.php" enctype="multipart/form-data">
			<table width="60%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td>Site Name: </td>
				<td><label>
				  <input name="site" type="text" class="text-box" id="site" />
				</label></td>
			  </tr>
			  <tr>
				<td align="left" valign="top">Description:</td>
				<td><label>
				  <textarea name="description" cols="30" rows="8" class="text-box" id="description"></textarea>
				</label></td>
			  </tr>
			  <tr>
				<td>URL:</td>
				<td><label>
				  <input name="url" type="text" class="text-box" id="url" />
				</label></td>
			  </tr>
			  <tr>
				<td>Image Name: </td>
				<td> <input name='image_name' type='text' class="text-box" /></td>
			  </tr>
			  <tr>
				<td>Image Path: </td>
				<td> <input name='image_to_upload' type='file' class="text-box" /></td>
			  </tr>
			  <tr>
				<td>&nbsp;</td>
				<td><label>
				  <input name="Submit" type="submit" class="button" value="Add To Portfolio" />
				</label></td>
			  </tr>
			</table>
			</form>
	   <p>&nbsp; </p></td>
	  </tr>
	</table></td>
  </tr>
  <tr>
	<td><a href="#top" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Footer','','images/footer_on.jpg',1)"><img src="images/footer.jpg" name="Footer" width="800" height="65" border="0" id="Footer" /></a></td>
  </tr>
</table>
</body>
</html>

I would appreciate any help? :) I'm learning PHP & MySQL

Thanks :)

#2 pixelDepth

    Young Padawan

  • Members
  • Pip
  • 6 posts
  • Location:Suffolk, UK

Posted 12 October 2006 - 09:01 AM

Check to make sure that the exif extension is loaded. :)

#3 Trix06

    Young Padawan

  • Members
  • Pip
  • 292 posts
  • Gender:Male
  • Location:NSW Australia
  • Interests:Web Design &amp; Development, Graphic Design, Programming, Networking, Girls, The Beach, Amatuer Radio Communications and more.

Posted 13 October 2006 - 04:18 AM

Sorry you have lost me? LOL

#4 pixelDepth

    Young Padawan

  • Members
  • Pip
  • 6 posts
  • Location:Suffolk, UK

Posted 13 October 2006 - 04:34 AM

To use the exif functions, the extension needs to be loaded, you should be able to check that by using the "extension_loaded" function like so...

if(extension_loaded("exif")){
	echo "Extension Loaded";
} else {
	echo "Extension Not Loaded";
}

:P

Edited by pixelDepth, 13 October 2006 - 04:34 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users