I am having a probelm with my code when updating news without a image. I can do it with a image and without but i get errors when i dont put in a picture. Here is the page
http://www.tjshafer.com/clients/projects/baintown/admin/index.php?page=news
Feel free to test.
Heres the error.
Warning: getimagesize: Unable to open '' for reading. in /usr/www/users/shafey7s/clients/projects/baintown/admin/newsadd.php on line 18
Here is the code
<b>News and news Image Upload: All Done</b>
<?
mt_srand((double)microtime() * 1000000);
$randomKey = (mt_rand(1,5000));
$date = date('Y-m-d',mktime($hour,$minute,0,$month,$day,$year));
if($image='')
{
$haveimage=1;//yes
}
if($haveimage!='1');
{
$dest='';
$uploadpath = "../dynamic_content/news/";
$image1= $FILES['image']['name'];
$source = $FILES['image']['tmp_name'];
$imagesize = getimagesize($source);
switch($imagesize[2])
{
case 0:
echo '<BR><FONT COLOR="RED">ERROR:</FONT> Image is not a JPG.<BR>';
break;
case 1:
echo '<BR><FONT COLOR="RED">ERROR:</FONT> Image is a GIF. It must be a JPG.<BR>';
break;
case 2:
$dest = "$uploadpath/$image1";
break;
case 3:
echo '<BR><FONT COLOR="RED">ERROR:</FONT> Image is a PNG. It must be a JPG.<BR>';
break;
}
if ( $imagesize[0] > 800 )
{
echo'<BR><FONT COLOR="RED">ERROR:</FONT> Image is '.$imagesize[0].' pixels wide. Images must not be more than 800 pixels wide and 600 pixels high.<BR>';
$denied = 1;
}
if ( $imagesize[1] > 600 )
{
echo'<BR><FONT COLOR="RED">ERROR:</FONT> Image is '.$imagesize[0].' pixels wide. Images must not be more than 800 pixels wide and 600 pixels high.<BR>';
$denied = 1;
}
if($dest!='' && $denied != 1)
{
if(move_uploaded_file($source,$dest))
{
$showimage='1';
}
else
{
echo'<BR><FONT COLOR="RED">ERROR:</FONT> File could not be stored due to file system error.<BR>';
}
}
}
$text = addslashes($text);
$teaser = addslashes($teaser);
$title = addslashes($title);
$result =mysql_query("INSERT INTO news (template,date_status,name,title,teaser,text,date) VALUES ('$template','$dateoff','$image1','$title','$teaser','$text','$date')") or die ("Couldnt Execute query".mysql_error());?>
<? echo"<br><b>Template id:</b>$template<br><b>Image Name:</b>"?>
<? echo $_FILES['image']['name'];?>
<br>
<?
if($turndateoff=='')
{
echo"<b>Date:</b>$date<br>";
}
echo"<b>Title:</b>$title<br><b>Teaser</b>$teaser<br><b>News:</b>$text";
if( $showimage='1')
{?>
<IMG SRC="../dynamic_content/news/<? echo "$image1?$randomKey";?>" WIDTH="375" HEIGHT="281" BORDER="0"><br>
<?
}
?>
Thanks a lot everyone. 🙂