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.
Related
I have been trying to change the images in the WampServer Index.php File... When I looked at the Index.php File I saw something Interesting. The File its self was containing the Image in the RAW format. Latter in the Code the PHP Script Calls the Image using the URL like http://localhost/index.php?img=pngFolder called a Image file stored RAW in the PHP file as a png.
Here is a link to a website that has the index.php code...
Link
I would Like to know how to replicate this same process to work for other images. Granted the File will be larger but its a Price to pay for what I am doing for a project. The Reason I want some help with this is so I can do it correctly. I have Tried 2 times already. I managed to get it to call one image correctly but not some of the others. I'm not sure if the image is just a different encoding or what..... Any Help would be Appreciated.
They are using BASE64 to encode the images into text. You can google for a base64 encoder that will convert your images to text. You can then put the text directly in an <img src="..base64 text.." />
Here's one..
https://www.base64-image.de/
As far as getting the image from the url index.php?img=pngfolder..
You could put this at the top of the file
if(isset($_GET['img'])){
echo "...base64 string.."; exit;
}
Then you can use the index url as the src for your image and it will simply retrieve the base64 image
I have built my website in a way so that the actual database files are positioned as follows
root/
root/httpdocs <- public folder
root/databasefolder/actual_files_here/some_photo.jpg
How can I implement so that the php can view/load a photo from that databasefolder and echo it with tag. I simply tried "../databasefolder/" in a tag, but it doesn't work (of course it doesn't), since it's from hidden folder.
I tried Base64 which works in other browsers, but not with Internet Explorer, due to that silly kb limit.
In your HTML:
<img src="image.php?image=some_photo.jpg" />
And a php script that echoes your image.
header('Content-type: image/jpeg');
echo imagejpeg('root/databasefolder/actual_files_here/' . $_GET['image']);
You can use the get parameter "image" to load whatever image you need from that folder.
image displays in the browser whrn the following code is used.But when the code is used inside html,the image does not appear instead a small box appear.
<?php
header('Content-Type: image/jpeg');
readfile('http://localhost/picture013.jpg');
?>
for example when i use no image is displayed.
<html>
<body>
<?php
header('Content-Type: image/jpeg');
readfile('http://localhost/picture013.jpg');
?>
</body>
</html>
in short i wanted to display all the images from a folder.
Maybe you can try this one
<?php
$dir = "localhost/image"; // your folder name ex: image
$imgs = glob($dir ."/*.jpg"); // get your image files with .jpg
foreach ($imgs AS $i) {
echo "<img src='$i'>"; //
}
?>
Think about what this is doing for a moment. That file already exists, you're not inventing image data from nothing, so why are you not just creating an element and link to that image?
Put an <img src="some/location/picture013.jsp"> on the page with an echo/print instead, and whatever page needs to show that image will work just fine. In this case it's already a legal URL, so you can just add <img src="http://localhost/picture013.jpg"> to whatever page needs it.
If it wasn't, you could make the server simply resolve the location you're pointing to with an .htaccess rule, or simply have the file live in an already web-visible directory. There is no reason to make PHP proxy the image data when it's already a normal web-visible resource; in fact, you're just over-complicating your code with unnecessary steps.
I'd like to store some photos in MySql as blobs and would like to be able to retrieve the binary and recreate images from it to display back to the user.
Everything I've search uses some combination of file_get_contents, Base 64 encoding and the GD library. But every post I come across has a different requirement than what I'm trying to do and so the code examples aren't that helpful.
Can someone tell me what function calls I need to make or give me an order of operations for what needs to be done. Say I have the following code:
$someBlob = getImageBlobByImageId(1203);
Say this blob represents an image named "foo.jpg". How do I go from $someBlob to foo.jpg so I could put it in HTML like
<img src="<?php echo $fooImage; ?>"/>
Any hints or nudges in the right direction are greatly appreciated ;-)
Your HTML needs to point to a PHP script that retrieves the blob and sends it back on request as an image.
For example, in your HTML:
<img src="getImage.php?id=1203" />
And then, for getImage.php:
<?php
$id = $_REQUEST['id'];
header("Content-type: image/jpg");
echo getImageBlobByImageId($id);
exit();
?>
Be sure not to have the script output any content other than the header line and the blob data, or you won't get what you want.
I have created a form which takes in images into a folder. I have only one image per folder and I want to display the image from the specified folder.
Say I've uploaded one picture to folder name uploads. Now I want to retrieve that image from the folder and display it.
How do I do that?
When a file is uploaded with your form, it becomes a file on your server, immediately. The web server puts it in a temporary directory and PHP tells you where it was put through the $_FILES array. You can immediately access this file, you can move it somewhere within your website's documents, and you can immediately print out an <img> tag pointing to where the file was put.
Stop writing "an img tag won't work" as that is exactly how you display the image.
Read the PHP manual page "Handling file uploads":
http://php.net/manual/en/features.file-upload.php
The PHP manual should always be the first place you go when you're trying to do something you haven't done before.
<img src="/path/to/the/upload/folder/<?php echo $filename; ?>"/>
or:
echo '<img src="/path/to/the/upload/folder/'.$filename.'"/>";
First you should have the image and path (or user) names in PHP variables. Then use an IMG tag to display them like :
<img src="some_path/uploads/<?php echo $username . '/' . $imagename; ?>">
you can't do it without knowing the name of the image file.
<?php
header('Content-Type:image/jpeg');
readfile('path_to_your/image.jpg');