Hi,

I have this image script and I want to upload the image and then save the file into a Database, but I keep on getting errors(a blank screen). Here's my code:

if(isset($_FILES['logo'])) {
				if(($_FILES['logo']['type'] == "image/jpg") || (($_FILES['logo']['type'] == 'jpeg') && (($_FILES['logo']['size'] < 524288)))) {
					
					$logoname = $_FILES['logo']['name'];
					$source = $_FILES['logo']['tmp_name'];
					$target = "../comLogos/".$logoname;								
					move_uploaded_file($source, $target);
					
					$imagepath = $logoname;
					$save = "../comLogos/logos/" . $imagepath;
					$file = "../comLogos/" . $imagepath;
					
					list($width, $height) = getimagesize($file);
					
					$modwidth = 150;
					$diff = $width / $modwidth;
					
					$modheight = $height / $diff;
					$tn = imagecreatetruecolor($modwidth, $modheight);
					$image = imagecreatefromjpeg($file);
					imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
					imagejpeg($tn, $save, 100);
					
					$logoPath = $_FILES['logo']['name'];
					$_SESSION['imageLogo'] = $logoPath;
					
				} else {
					$logoPath = '../comLogos/no_image.jpg';
					$_SESSION['imageLogo'] = $logoPath;
				}
			} else {
					$logoPath = '../comLogos/no_image.jpg';
					$_SESSION['imageLogo'] = $logoPath;
			}

Here are my SQL statements:

if (empty($reg_errors)) { // if everythings okay
				
					$q = "INSERT INTO Company(CompanyName,CompanyWebsite,CompanyEmail,CountryCode)VALUES('$companyName','$companyWebsite','$companyEmail','$companyLocation')";
					$r = mysqli_query($dbc, $q);
					
						if(mysqli_affected_rows($dbc) == 1) {
						
							$companyID = mysqli_insert_id($dbc);
							$_SESSION['companyID'] = $companyID;
							
							//echo "{$_SESSION['companyID']}";
							$q = "INSERT INTO Logos(CompanyID,logoPath)VALUES({$_SESSION['companyID']},{$_SESSION['imageLogo']})";
							$r = mysqli_query($dbc, $q);
							
								if (mysqli_affected_rows($dbc) == 1) {
									echo 'Test Worked';
								} else {
									echo 'problem with image upload';
								}
							
						} else {
							echo 'problem with company insert';
						}
				} // End Errors Condition

I know it has something to do with the image as if I take out the image session in the Insert query it will input the companyID into the logos table.

Any help would be much appreciated.

Hi,

Thanks for the link but I didn't understand that, if anyone has some productive information on how I could fix it, it would be much appreciated.

The

if(isset($_FILES['logo']))
{

}
else
{
$logoPath = '../comLogos/no_image.jpg';
$_SESSION['imageLogo'] = $logoPath;
}

Should work fine, their is nothing wrong with $_FILES command ?

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.