Jump to content

form with image uploader


fife

Recommended Posts

Hi.  I have a piece of code that uploads an image. It works great.  Ive added it to some more coding inserting information into a database.  Now the code doesn't work. I have used some error reporting and i get

 

Notice: Undefined index: newImage in /home/sites/submitpost.php on line 9

 

Notice: Undefined index: newImage in /home/sites/submitpost.php on line 10

 

Notice: Undefined index: newImage in /home/sites/submitpost.php on line 11

 

Notice: Undefined index: newImage in /home/sites/submitpost.php on line 12

 

Here is the code.  Can someone explain whats wrong?

 

include('database.php');
session_start();
//another photo uploader
$fileName9 = $_FILES['newImage']['name'];
$tmpName = $_FILES['newImage']['tmp_name'];
$fileSize = $_FILES['newImage']['size'];
$fileType = $_FILES['newImage']['type'];	


//$randName = md5(rand() * time());
//$fileName9 = $randName + $fileName9;
$limit_size=2097152;
$folder = "{$_SERVER['DOCUMENT_ROOT']}/images/memberImages/";


if ($fileSize >= $limit_size){$msg1="Your uploaded file size is more than 2MB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
$success=0;}	

elseif ($fileName9=="") {$error = "Please choose a file to upload"; $success=0;}

//elseif ($fileType!== 'image/jpeg' || 'image/gif' || 'image/png' || 'image/JPG') {$error = "false";}

$types = array('image/jpeg', 'image/gif', 'image/png', 'image/JPG', 'image/pjpeg', 'image/x-png');

if (in_array($fileType, $types)) {

if(move_uploaded_file($tmpName , $folder.$fileName9)) {

$Fnew1 =  $fileName9;
$place=mysql_real_escape_string($_POST['place']);
	$cityname=mysql_real_escape_string($_POST['cityname']);
	$city=mysql_real_escape_string($_POST['city']);
$title=mysql_real_escape_string($_POST['ComTitle']);
$message=mysql_real_escape_string($_POST['commentDescrip']);
$member=mysql_real_escape_string($_POST['member']);
$time=time();

mysql_query("INSERT  INTO posts (type, title, message,postUserID, time, cityID, status, place, image) VALUES('$type','$title','$message','$member', '$time', '$city', '1', '$place', '$Fnew1')") or die('post error');

$id = mysql_insert_id();

$url = "/view-thankyou.php?city=$cityname&type=$type#name";  
header("Location: $url");   

}

else

{echo"Move fail";  }


}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/255884-form-with-image-uploader/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.