Hi
I have used this file numerous time and it always worked, and I out of the blue I get this error now i have checked the script but i cant seem to find anything wrong.
<?
function upload_image($img, $ext, $id) {
$uploadpath = $_SERVER["DOCUMENT_ROOT"].'/css/news-images/';
if ( ($img != 'none') && ($img != '' ) ) {
$imagesize = getimagesize($img);
switch ( $imagesize[2] ) {
case 0: //cannot use this image type.
break;
case 1: //gif.
$dest = $uploadpath."News_".$id.'_'.$ext.'.gif';
$img_fname = "News_".$id.'_'.$ext.'.gif';
break;
case 2: //jpg.
$dest = $uploadpath."News_".$id.'_'.$ext.'.jpg';
$img_fname = "News_".$id.'_'.$ext.'.jpg';
break;
case 3: //png.
$dest = $uploadpath."News_".$id.'_'.$ext.'.png';
$img_fname = "News_".$id.'_'.$ext.'.png';
break;
}
if ( isset($dest) ) {
if ( move_uploaded_file( $img, $dest ) ) {
chmod ($dest, 0777);
}
}
}
return ( isset($img_fname) ) ? $img_fname : "";
}
if ($_POST['Submit']) {
if ($_POST['Title']=="") {
$title_error = "<span class='admn-error'>You must enter a title for the news article.</span><br />";
}
if ($_POST['News']=="") {
$story_error = "<span class='admn-error'>You must enter the content for the news article.</span><br />";
}
if ( !isset($title_error) && !isset($story_error) ) {
//first we insert the data from the form.
$sql = "INSERT INTO latest_news (
ID,
Title,
News,
Date
) VALUES (
'',
'".$_POST['Title']."',
'".$_POST['News']."',
str_to_date('".$_POST['date']."', '%d-%m-%Y')
)";
$result = mysql_query($sql) or die (mysql_error());
$id = mysql_insert_id();
//now we upload the images to the hdd and get the image name(s).
$image1 = upload_image($_FILES['image1']['tmp_name'], 1, $id);
$image2 = upload_image($_FILES['image2']['tmp_name'], 2, $id);
//and we put the image name(s) into the database so we can see them later.
$sql = "UPDATE latest_news SET
Image_name1 = '".$image1."',
Image_name2 = '".$image2."'
WHERE ID = '".$id."'";
$result = mysql_query($sql) or die (mysql_error());
//if everything was successful we thank the user for the submission.
if ($id) {
$msg = "<span class='error'>Thank you! The new news article has been created. You can see it <a href='view-news.php?ID=".$id."' target='_blank'>here</a>.</span>";
} else {
$msg = "<span class='error'>Sorry! Unfortunately something was wrong with your submission, please try again later.</span>";
}
}
}
?>