I am having some problems with get image size. I get the following error
Warning: getimagesize: Unable to open '' for reading. in /usr/www/users/shafey7s/clients/projects/baintown/admin/review_news.php on line 123
Heres the script
<?
switch ($mode) {
case view:
$result = @("SELECT title, teaser, name, id, text, UNIX_TIMESTAMP(date) as date FROM news") or die("Couldn't ececute query.".mysql_error());
echo"<table border=0 cellspacing=0 cellpadding=2>
<tr><td><span class='copy12'>Choose the news you would like to edit or delete.</span><br><br></td><td></td></tr>";
$n = 0;
while($row = mysql_fetch_array($result)) {
$convertedDate = date('F j, Y', $row[date]);
if ($n == 0) {
$tableBG = "#DDDDDD";
$n++;
} else {
$tableBG = "#BBBBBB";
$n = 0;
}
echo"<tr bgcolor=$tableBG><td class='copy12'><b>$convertedDate</b></td><td></td>
</tr><tr bgcolor=$tableBG><td class='copy12'>$row[title]- $row[id]<br><br>";?>
<? echo nl2br($row[teaser]) ?> <? echo nl2br($row[text]) ?></td>
<? echo"<td valign='top'>
<a href='index.php?page=viewnews&mode=edit&id=$row[id]' class='menurollover'><b>Edit</b></a><br>
<a href='index.php?page=viewnews&mode=delete&id=$row[id]' class='menurollover'><b>Delete</b></a></tr>
";
};
echo"</table>";
break;
case edit:
$db = @mysql_select_db($dbname, $connection) or die("Couldnt select database.");
$result = @("SELECT title, teaser, name, text, id, UNIX_TIMESTAMP(date) as date FROM news where id='$id'") or die("Couldn't ececute query.".mysql_error());
while($row = mysql_fetch_array($result)) {
echo"<form action=index.php?page=viewnews&mode=updatenews&id=$row[id] method='post'>
<span class='copy12'><b>News Article Number : $row[id]</b>
<br>
<br>
$row[title]<br>
<b>Date:</b>
<select name='month' class='copy10'>";
for ($x=1;$x<=12;$x++) {
if ($x==date('n',$row[date])) {
echo"<option value=".$x." selected='selected'>".date('M',mktime(0,0,0,$x,1,2000))."</option>";
} else {
echo"<option value=".$x.">".date('M',mktime(0,0,0,$x,1,2000))."</option>";
}
}
?>
</select>
<select name='day' class='copy10'>
<?
for ($x=1;$x<=31;$x++) {
if ($x==date('j',$row[date])) {
echo"<option value=".$x." selected='selected'>".$x."</option>";
} else {
echo"<option value=".$x.">".$x."</option>";
}
}
?>
</select>
<select name='year' class='copy10'>
<?
for ($x=2002;$x<=2012;$x++) {
if ($x==date('Y',$row[date])) {
echo"<option value=".$x." selected='selected'>".$x."</option>";
} else {
echo"<option value=".$x.">".$x."</option>";
}
}
?> </span>
</select> <br>
<br><b>Title:</b>
<input type='text' name='title' size='50' value='<? echo"$row[title]";?>'>
<br><b>Teaser:</b>
<textarea name='teaser' cols='50' rows='20'><? echo "$row[teaser]";?></textarea>
<br>
<br><b>News:</b><textarea name='text' cols='50' rows='20'><? echo"$row[text]";?></textarea>
<br>
<b>Change Image or add Image:</b><br>
<? if ($row[name]=''){?>
<IMG SRC="../dynamic_content/news/<? echo "$name";?>" WIDTH="375" HEIGHT="281" BORDER="0">
<? }else{};?>
<br>
<input type="hidden" name="fieldName" value="">
<A HREF="javascript:popUp('templates.php?id=1')" class="copy12">Template option 1</A><br>
<A HREF="javascript:popUp('templates.php?id=2')" class="copy12">Template option 2</A><br>
<A HREF="javascript:popUp('templates.php?id=3')" class="copy12">Template option 3</A><br>
<b>Template</b><br>
<select name="template" class="select">
<option value="1">Template 1</option>
<option value="2">Template 2</option>
<option value="3">Template 3</option></select><br>
Note that images must be:
<UL>
<LI> 375 pixels wide and 281 pixels tall
<LI> a JPG file
<LI> under 70k in size (recommended size - under 35k - use compression to achieve this)
</UL>
<br><p>
<INPUT TYPE="file" NAME="image" SIZE="30">
<br>If you select a image it will replace the current image with the one selected.<br>
<input type='submit' name='Submit' value='Update News' class='copy10'> </form>
<? }
break;
case updatenews:
mt_srand((double)microtime() * 1000000);
$randomKey = (mt_rand(1,5000));
$date = date('Y-m-d',mktime($hour,$minute,0,$month,$day,$year));
$dest='';
$uploadpath = "../dynamic_content/news/";
$image1= $_FILES['image']['name'];
$source = $_FILES['image']['tmp_name'];
if($_FILES['image']['size'] == '0') {
} else {
$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>';
}
}
}
//Filter Nasty Stuff
$text = addslashes($text);
$teaser = addslashes($teaser);
$title = addslashes($title);
$result =mysql_query ("update news set template='$template',date_status='$dateoff',name='$image1',title='$title',teaser='$teaser',text='$text',date='$date'") or die ("Couldnt Execute query".mysql_error());
if ($ampm=="PM" and $hour<>12)
{
$hour = $hour + 12;
}
if ($ampm=="AM" and $hour==12)
{
$hour = 0;
}
echo"<br><b>Template id:</b>$template";
if($_FILES['image']['size'] == '0') {
} else {
echo"<br><br><b>Image Name:</b>";
echo $FILES['image']['name'];
}?>
<br>
<?
if($turndateoff=='')
{
echo"<br><b>Date:</b>$date<br><br>";
}
echo"<b>Title:</b>$title<br><br><b>Teaser</b>$teaser<br><br><b>News:</b>$text";
if( $showimage='1')
{
if($FILES['image']['size'] == '0') {
} else {
?>
<IMG SRC="../dynamic_content/news/<? echo "$image1?$randomKey";?>" WIDTH="375" HEIGHT="281" BORDER="0"><br>
<?
}
}
break;
case delete:
$result = @("delete from news where id ='$id'") or die("Couldn't ececute query.".mysql_error());
echo"<span class='copy12'>News article number $id deleted.</span>";
break;
};
?>
heres the script running
http://www.tjshafer.com/clients/projects/baintown/admin/index.php?page=viewnews&mode=edit&id=111
go ahead and try it out