Ok, so here is what I am looking to do...I want to be able to upload a picture to the specified folder, and the path is inserted into the database(That part is done)
Then I need to pull the images from the database and display them on the index.php page. I know it's a simple process but I must be missing something.(grrr) I just can't seem to get the image to display on the index.php page, I can display the file location on getimage.php and echo out the image, but can't seem to reference the location to the img src and get it to display on index.php
Here is the code for the index.php page:
I want to be able to pull the image from getimage.php and display the image on the index.php page.
<a href="gallery.html">
<img src="getimage.php?id=18" alt="" width="200" height="133" /></a>
Here is the getimage.php page:
<?php
include("connect.php");
$id = mysql_real_escape_string($_GET['id']);
$sql = mysql_query("SELECT * FROM pictures WHERE p_id='$id'");
while($row = mysql_fetch_array($sql))
{
header("content-type :image/jpeg");
$image = $row['image'];
echo $image;
}
?>
So what this script is going to do is:
On the index page there are 3 pictures, there will be preset slots in the database for them. The user will be able to change these 3 photos anytime by uploading another photo (the upload script will update the old ones with the new ones.) the pictures will be displayed by their ID.
I could simply run 3 queries, 1 for each ID but I was thinking maybe i'm missing an easier way to do it.
Help is very much appreciated...Thank you.
(Yes I am aware of SQL injection as well as deprecation)
Your code is absolutely not correct correct. You have to change the line to :
echo '<img src="data:image/jpeg;base64,'
.base64_encode($image['file_data']).'" width=300 height=200/>";
Related
I've created a simple website on which you can register, then log-in and be able to upload images which are then displayed on the index page. Each displayed image leads to a url
uploads/".$imagePath."
which displays the image in it's full size in a new url. Unfortunately that url only contains the image but I would like to include image information, header, footer, etc. Obviously if the url led to a page that I have created, I could simply include header,footer and the stuff I need but since it's unique for every image, I have absolutely no idea what to do about it. Here's my code
echo "<br>"
.$getResult['name'].'<br><br>'
."<a href='uploads/".$imagePath."'>".'<img class="uploadedImg" src="'.$image .'" alt="Random image" /></a>'."<br><br>"
.$getResult['description']."<br><br>"
.$getResult['date']."<br><br>"
.$getResult['author']."<br><br>";
For each image, instead of giving image as hyperlink to large image, give a hyperlink to php file as follows:
<a href="imageinfo.php?id=<?php echo $image_id;?>">
<?php echo "<img class='uploadedImg' src=$image alt='Random image' />"?>
</a>
Along with the 'imageinfo.php' file, pass unique id of the large image information row, that is stored in database, which you are planning to include in your header and footer.
In the 'imageinfo.php' file you can access this $image_id as $_GET['image_id']. Using which you can get the data from database and display.
So all the images will be hyperlinked to same 'imageinfo.php' file but based on the id send with it the Large image and its associated header and footer can be fetched from database and displayed.
Happy Coding!
I have this problem, i have this script in php that creates a image on the fly, the problem is that the outputted image on the browser is allright, but i need to change it's name.
Ex: Index.php
<?php $url = "http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33" ?>
<img src="<?php echo $url ?>" />
The image_scrc.php is the file that creates the image, and as you can see i have several data that is passed by the get method.
In the image_scrc.php i have tryed
header('Content-type: image/jpg');
header('Content-Disposition:inline; filename="'.$random_name_jpeg.'"');
but the html link is is always appearing like this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
if i select the image on browser and then select copy image link it copies just like this also.
however, when I save the image it assumes the random_name.jpg, but only on save!
i've tried everything, even htaccess rules but nothing seems to work !!
it's this possible to acomplish? transform this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
to this
http://www.somesite.com/cls/random_name.jpg
i cant have the image on the server side! and must be displayed on the fly
Thanks in advance.
I save my image name to my database and image itself to upload file.
When the user want to see them, I want to show them to user with in a div.
Here things get messy in my mind.
here is my php code
$con = mysql_connect("localhost","root","");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("marmaris", $con);
$bilgi= mysql_query("SELECT * FROM ".$isim." WHERE id='".$id."'");
while($sutun= mysql_fetch_array($bilgi))
{
$name=$sutun["name"];
$bures=$sutun["resbuyuk"];
$kures=$sutun["reskucuk"];
$aciklama=$sutun["aciklama"];
$map=$sutun["map"];
$link=$sutun["link"];
}
$words = preg_split('/[\s?]+/', $kures);
$result = count($words);
for($i=0;$i<$result;$i++){
$city=$words[$i];
}
i got 6 images now $city is one of the image forexample i want to show the user that image.
this is my html part don't worry about the isimid name its just sending 2 words at one time.
<div id="kucukres">
<img src="upload/<?php echo $city ?>" alt="Angry face" width="32" height="32" />
</div>
I want to show the image but it only writes the alt words.
In summary, I want to show image that has saved (the name) in database and itself in the upload folder.
With php part, I take the name of the file from database; in html, I want to show that image.
edit :
this is my new html tag.
<div id="kucukres">
<img src="getres.php?file=<?php echo $isimid;?>"/>
</div>
and my php file is
$bilgi= mysql_query("SELECT reskucuk FROM ".$isim." WHERE id='".$id."'");
while($sutun= mysql_fetch_array($bilgi))
{
$kures=$sutun["reskucuk"];
}
$words = preg_split('/[\s?]+/', $kures);
$result = count($words);
//unlink("upload/$word[$isim]");
for($i=0;$i<$result;$i++){
$city=$words[$i];
header('Content-type: image/jpeg');
$pic = 'upload/'.$city;
echo $pic;
but still i cant see the image in my html file.
There is no shortage of tutorials and samples on this subject.
Essentially, what you're trying to do involves two PHP files, not just the one that you have. You'll need one for the page and one for the image (which can be re-used for all images).
Start by taking a look at the HTML that's rendered for your page. What is the img tag referencing? It's looking for a resource (image file) on the server that isn't there, so naturally it's not displaying anything. Your server logs will also show you the 404 errors for those image requests.
This is because the image isn't really part of the page. It's an entirely separate resource that the page is just referencing, the browser's job is to put it in place. So you need to create a separate resource (PHP file) to serve that image.
My PHP is a bit rusty, so I'll defer to the many examples and tutorials online for the specifics. But the structure would basically be as such:
Page A, the host page:
Fetch from the database information about the image. Its ID, its alt text if applicable, etc. Use this information to build the img tag. Something like:
echo '<img src="/images/dbimage.php?id=' . $id_from_db . '" alt="' . $alt_from_db . '"/>';
Page B, the image page:
Fetch the actual image (blob) from the DB and its content-type if that's also dynamic. Write no output before this is done. Set the response header's content-type to the content-type of the image, write the raw image bytes as output, end the output.
The main thing to remember, again, is that the image isn't being sent to the browser as part of the page. It's an entirely separate resource fetched from an entirely separate request to the server. You just need to handle that request separately from the page itself.
(Note, for example, that if you then navigated to the URL generated for the img tag then the server would display just the image. The host page isn't needed.)
I have a form which lets users upload an image in PHP, and the image is then stored in a file located in my root folder called 'avatars', but it is referenced in my main MySQL table - this is the processing bit in my php.
move_uploaded_file($_FILES["clogo"]["tmp_name"],
"avatars/" . $_FILES["clogo"]["name"]);
What i want to do is display this image next to the relevant entry but i'm having difficulty with it. Below is how i am displaying other information from the table (having performed the query to that table and stored everything in $rsjobinfo)
<li id = "compname"><?php echo $rsjobinfo['company_name'];?></li>
I was trying this but its obviously wrong!
<img src = "avatars/" <?php echo $rsjobinfo['clogo'];?>/>
Can anyone help?
Thanks
Dan
You're putting url outside of quotation marks.
Should be just
<img src = "avatars/<?php echo $rsjobinfo['clogo'];?>"/>
assuming $rsjobinfo['clogo'] returns the correct file name.
I've saved a user's respective picture in a folder named 'profileportraits'. So when a user uploads their picture, it is saved into that folder. Furthermore, I also save the 'portrait path', i.e. the location/name of the photo onto a MySQL database for user data. My question is: I am able to echo the Portrait Path, where the user's portrait is stored onto the page. But how will I display the actual photo onto the page? I.e. how can I turn the file path into the actual picture? Will I have to match the path that I retrieved from MySQL to the directory? or something else? Below is a bit of code.
{
echo $row['PortraitPath'];
}
With the code above, I am able to echo the actual path, which is: profileportraits/DSC00310.JPG. I simply want to turn this path of the picture, into the actual picture. Thank you.
<img src="<?php echo $row['PortraitPath']; ?>" />
or
<?php
echo "<img src=\"{$row['PortraitPath']}\" />";
?>
Why not use the path as the source of an image tag:
echo "<img src=\"{$row['PortraitPath']}\" />"