Jump to content

Help with image upload error


neogemima

Recommended Posts

I am trying to upload 3 images to accompany a user's post, and keep getting returned my else statement for the mysqli query failing.  I can't figure what is going wrong.

 

Here is my code:

<?php
//create short variable names

$maxfilesize= 150000;
$date= date("Y/m/d");
$title=$_POST['title'];
$type=$_POST['type'];
$email=$_POST['email'];
$price=$_POST['price'];
$equipmentcontent= str_replace("\n", "<br>", $_POST['equipmentcontent']);

if (!$title || !equipmentcontent || !$type || !$email) {
	echo "Please fill out the title, type of equipment, email, and the content of your post before proceeding.<br>";
	exit;
	}

if (!get_magic_quotes_gpc()) {
	$title = addslashes($title);
	$equipmentcontent = addslashes($equipmentcontent);
	$type = addslashes($type);
	$email = addslashes($email);
	$price = addslashes($price);
	$img1 = addslashes (file_get_contents($_FILES['img1']['tmp_name']));
	$img2 = addslashes (file_get_contents($_FILES['img2']['tmp_name']));
	$img3 = addslashes (file_get_contents($_FILES['img3']['tmp_name']));
	}


if ((($_FILES['img1']['type'] == "image/gif") || ($_FILES['img1']['type'] == "image/jpeg") || ($_FILES['img1']['type'] == "image/pjpeg")) && (($_FILES['img2']['type'] == "image/gif") || ($_FILES['img2']['type'] == "image/jpeg") || ($_FILES['img2']['type'] == "image/pjpeg")) && (($_FILES['img3']['type'] == "image/gif") || ($_FILES['img3']['type'] == "image/jpeg") || ($_FILES['img3']['type'] == "image/pjpeg")) && ($_FILES['img1']['size'] <= 150000) && ($_FILES['img2']['size'] <= 150000) && ($_FILES['img3']['size'] <= 150000))

{

@ $db = mysqli_connect('xxxxxxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxxxx');


if (mysqli_connect_errno()) {
	echo "Error: Could not connect to database.  Please try again later.";
	exit;
	}

	$query = "INSERT INTO Equipmentposting (date, type, title, price, email, content, img1, img2, img3) VALUES ('$date', '$type', '$title', '$price', '$email', '$equipmentcontent', '$img1', '$img2', '$img3')";
	$result = mysqli_query($db, $query);


if ($result) {
	echo '<font color="#666666">';
	echo 'Thank you.<br><br>';
	echo '<font color="#000000">'.mysqli_affected_rows($db).'</font> posting has been uploaded to the site.<br><br>';
	echo 'This posting will remain on the site for 30 days and can be seen in our <a href="http://www.biotechposting.com/pages/equipment.html" target="_parent">Equipment Classifieds</a> section.';
	echo '<br><br>';
	echo '<font size="-1">';
	echo 'This service will remain free for the first few months of activity on BioTechPosting after which it will be a flat fee of $20 to post regardless of your location.  Accompanying a post of this kind, you will also be able to post free industry news, a regular $20 value.<br>';
	echo '</font></font>';
	echo '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>';
	} else {
		echo "An error has occured.  Your post was not added.";
	}

mysqli_close($db);

}

else
	{
	echo "Image files exceed maximum upload size of 150K or are an invalid format.<br>";
	}



?>

 

The return is the "An error has occured.  Your post was not added."

 

The only part of the images I want to upload to the database is the content itself so that I can call it to a web page and display the images.

 

Does anyone know why the query is failing?

Link to comment
Share on other sites

I am getting this error:

 

Warning: file_get_contents(BETA-UNDER-CONSTRUCTION.jpg) [function.file-get-contents]: failed to open stream: No such file or directory

 

for each image.  I am reading many tutorials that use different methods.  Can I not get the file and encode it directly into my mysql table of field type blob?  Or do I need to create an upload file on my server to house the images and access them that way.  If so, can someone elaborate on how this is done?  Thanks.

Link to comment
Share on other sites

I think I have narrowed down my problem.  Because the file path that is uploaded to the server (hosted by GoDaddy) is not local to the computer uploading the files over the internet, the file paths are invalid.  How can I get around this?

 

Or, how in general can I upload a BLOB over the internet?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.