thanx........for u r reply......... orjan
but i could not get u .......
to put the below script and call the fetch.php page.........as it will b feching images with respective 'id'......
your code.........
similar to this:
PHP Code:
i tryed it .........i am able to get only image icons.........but not the images in the web pageCode:$query = mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
while($row = mysql_fetch_array($query)){
$id = $row[id];
echo "<img src='fetch.php?id=$id'>";
echo $row[comment];
}
here is my code
all_imgs.php =======>from this page i am calling fetch.php
//===============================================Code:<?php
header('Content-type: image/jpeg'); // act as a jpeg file
mysql_connect('localhost','root','')or die(mysql_error());
@mysql_select_db('test')or die(mysql_error()); // use the ‘test’ database
$query = mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
while($row = mysql_fetch_array($query))
{
$id = $row[id];
echo "<img src='fetch.php?id=$id'><br>";
echo $row[comment];
}
?>
and here is the
code for fetch .php (.........your code)
can u post the whoe code.........Code:<?
if(isset($_GET['id']))
{
header('Content-type: image/jpeg'); // act as a jpeg file
mysql_connect('localhost','root','')or die(mysql_error());
@mysql_select_db('test')or die(mysql_error()); // use the ‘test’ database
$query = 'select * from images where id = $id';
$result = mysql_db_query('test',$query)or die(mysql_error());
$row = mysql_fetch_array($result);
$img = $row['img'];
echo ($img);
}
else{echo 'id is not send';}
?>
and how can i show the id,title,img .........all at one place from the img table
which fields say as imagestable (id,title,img,description)
thax in advance
Last edited by Jaan; 12-21-2008 at 04:03 AM. Reason: Please use code tags when you're posting your codes!
Too tired right now to post full codes. But no, it's not possible to do everything from one file.
you need one php to show the pictures, and another one to create the html-page that includes the pictures.
the php-file to show the pictures is in full shown in the first posting with the tutorial.
the other php-file where you read out the surrounding data is built after how you want it. but in general, it's where you read out everything from the database but the picture itself.
when i'm trying to show images, i got something like this:
h t t p : / / img156.imageshack.us/my.php?image=imagerf8.jpg (remove spaces, i'm new here and not able to post links, but there is what i get)
i really don't know what's the problem
my code is:
please help meCode:<?php
$username = "root";
$password = "mypassword";
$host = "localhost";
$database = "scientific";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$id = $_GET['id'];
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM article WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['photo'];
header('Content-type: image/jpg');
echo $content;
}
?>
Thanks
You get that.. because I don't know why..
This is wierd.. It should display this:
Code:die("Please select your image!");
well.. i tried another way. so in this way image should be displayed.. but it doesn't! and i really don't know why
here is the code:
form.html
insert.phpCode:<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>add pic</title>
</head>
<body>
<form action="insert.php" method="post" enctype="multipart/form-data" name="changer" >
<input name1="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpg" type="file">
<input value="Submit" type="submit">
</form>
</body>
</html>
and printimage.phpCode:<?php
$username = "root";
$password = "mypassword";
$host = "localhost";
$database = "scientifc";
// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Select your database
mysql_select_db ($database);
// Make sure the user actually
// selected and uploaded a file
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
// Temporary file name stored on the server
$tmpName = $_FILES['image']['tmp_name'];
// Read the file
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
// Create the query and insert
// into our database.
$query = "INSERT INTO article ";
$query .= "(title,text,domain_id, photo,validat) VALUES ('sdfdsdfsds','ssdafdfg',3,'$data',1)";
$results = mysql_query($query, $link);
// Print results
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
// Close our MySQL Link
mysql_close($link);
?>
record with id 22 contains an image, in the column photoCode:<?php
$username = "root";
$password = "mypassword";
$host = "localhost";
$database = "scientific";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
//$id = $_GET['id'];
$id = 22; // just a test id to see if it works!
if(!isset($id) || empty($id)){
die("Please select your image!");
}else{
$query = mysql_query("SELECT * FROM article WHERE id='".$id."'");
$row = mysql_fetch_array($query);
$content = $row['photo'];
header('Content-type: image/jpeg');
echo $content;
}
?>
where the f... is the problem?
Well.. Do you have a table called a "photo" ? or something.. I believe it don't get dat pic from the database, that's why it don't work..
thanks for your tutorial!
it just downloads the show.php to my HD automatically for me. But dude, I am totally new to php and creating databases as of well...... an hour ago. Got the database working and I can see there are several BLOBS that got created. I assume those are the images but not sure how to actually view them in the browser window.
Last edited by jpresch; 01-23-2009 at 08:31 PM.
LOL....You actually have to display it in an html page....WORKS Perfect! Thanks you rock. good tut, if I can figure it out with no previous experience you did well my man.
Hi guys
My problem is similar to what was mentioned before:image is displayed as a raw file...I tried to remove all the html info that were before and after the php tags but didn't do the trick.Here is the code, hope one of you might be able to help.Thanks in advance...
Code:<?php
echo "<p>Recent uploads</p>";
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'root');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the pictures database
if (!@mysql_select_db('pictures')) {
exit('<p>Unable to locate the Pictures ' .
'database at this time.</p>');
}
// Request the id, title, img of files
$result = @mysql_query('SELECT id, title, images FROM details');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display $result in a paragraph
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$title = $row['title'];
$img = $row['images'];
header('Content-type : image/jpg');
echo '<blockquote>' . $id, $title, $img .'</blockquote>';
}
?>
Last edited by Jaan; 02-02-2009 at 07:50 AM. Reason: Please use code tags when you're posting your codes!
There are currently 3 users browsing this thread. (0 members and 3 guests)
Bookmarks