Jump to content

Recommended Posts

Hi there, I have three PHP pages, in which one is to upload a picture to a database, and the other two work together and post the image... although that's what it's supposed to do.

 

Here is the code for the uploading script, i think this one is fine (named ImageInserter.php):

 

<?


$host = '********************.com';
$username = '*********';
$password = '*********';
$db = '***********';


$Picture = "10.jpg"; // This is just one of the images that i was uploading


If($Picture != "none") {


$PictureData = GetImageSize($Picture);
$PSize = filesize($Picture); // Get the file Size
$PWidth = $PictureData[0]; // Get the Picture Width
$PHeight = $PictureData[1]; // Get the Picture Height
$PFormat = substr($Picture_name, strlen($Picture_name)-3, 3); // Get the file extension
$mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize)); // Get the picture ready to insert into a db
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
mysql_query("INSERT INTO Images (Image) VALUES ('$mysqlPicture')") or die("Can't Perform Query");
echo ("Picture Has Been Inserted");
}


else {
echo ("Error");
}
?>

 

 

The next file is the first of the publishers (named FirstType.php):

 

<HTML>
<BODY>


<form method="get">
Enter Number: <input type="number" name="number"> //Here i was trying to use a method
<input type="submit" value="Submit"> //In which the users inputs a number
</form> //Which relates to a picture in DB


<?
$host = '**********.com';
$username = '*********';
$password = '*********';
$db = '**********';

$PicNum = $_GET["number"];

mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$result=mysql_query("SELECT * FROM Images WHERE PicNum = $PicNum") or die();
While($row=mysql_fetch_object($result)) {
echo "<IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\">";
}



?>
</BODY>
</HTML>

 

 

And finally the last file which is related at the end of the previous one (named SecondType.php3):

 

<?
$host = '***************.com';
$username = '**************';
$password = '************';
$db = '***********';
$PicNum = $_GET['number'];


mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$result = mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum")or die("Can't perform Query");
$row = mysql_fetch_object($result);
Header("Content-type: Image/JPG");
echo $row->Image;
?>

 

The main problem is that when i enter the number, it displays as a broken image.

 

 

Thanks to anyone who can help me out with this :)

Edited by swiss_toni
Link to comment
https://forums.phpfreaks.com/topic/273931-pulling-an-image-from-a-database/
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.