I have a php file that outputs a image with dynamic content.
I need to get the url of the img using it. Example: www.bla.com/
<img src="signature.php?color=black">
The php would return www.bla.com/
Can I do this WITHOUT using GET vars and php on the img page?
Thanks to #Terminus for helping, my solution was to use:
$_SERVER["HTTP_REFERER"]
Then do some sanitizing just in case.
Related
I have img tags that have parameters as part of the url. These parameters are used for an ajax image crop. They look like this
<img src="/resize/45-800/files/myImage.jpeg" alt="Chania">
By adding /resize/45-800/ in front of the url
I am able to tell the ajax script to get that file from the files directory, and dump a cropped version into /resize/files/
My question is, is there a way to remove these parameters 45-800/, which can be different each time, for file reading purposes only, so that html will read for the image like this
<img src="/resize/files/myImage.jpeg" alt="Chania">
but the world will see the src still like this
<img src="/resize/45-800/files/myImage.jpeg" alt="Chania">
Is this possible using htaccess?
I know I could use a query string and just use the ajax script to read from the src like this
<img src="/resize/files/myImage.jpeg?params=45-800" alt="Chania">
I was just hoping for a prettier way. I don't really want to use the question mark '?'.
The /resize and /files will always be there every time.
Does anyone know of a way?
I just had an epiphany... I could just put the crop width and height parameters in data attributes instead of in the url... So this
<img src="/resize/files/myImage.jpeg" data-wh="45-800" alt="Chania">
Instead of this
<img src="/resize/45-800/files/myImage.jpeg" alt="Chania">
Then I can serve them from the resize/files/ directory for all images that have the resize parameter passed into the url; and I don't have to use an ugly query string.
"/resize/45-800/files/myImage.jpeg?ugly=45-800"
So I haven't tested this, but I think I found the legit answer to my original question. I know its possible as the people at the last job I worked at used to resize images based on src url params. Here is the link - http://sneak.co.nz/projects/img-resizing/
My plugin is already finished and working now 8/ This method looks a little nicer though, they walk you through the whole image resize process, and use image caching as well.
Hope this helps someone as much as it does me if it works! I'll leave a comment if I end up testing it out and it works well.
i am displaying an image usign readfile() function of php
HMTL:
<img src='image.php?id=232'/>
PHP: image.php
<?php
$id=$_GET["id"];
if(image_view_allow($id)){
$path=get_image_path($id);
readfile($path);
}else{
readfile("images/not_allow.png");
}
image_view_allow and get_image_path is two that i have defined to check validation and get path
I am doing this because i want show image only to the allow person.
Does this affect speed of downloading an image ?
what is normal(means direct path in src attribute of img tag) or trick that is shown above?
Just loading an image probably same,but it is always better if you handle images with php, because when you resize image with php you load the needed size. But with html you load the bigger size than you need and resize.
first -> Does this affect speed of downloading an image ?
answer: no, because when the page is loaded, the php code is already translated to html before page is loaded in the borwser.
second -> what is normal(means direct path in src attribute of img tag) or trick that is shown above?
answer: both are same as both involve php code. When code executes in either way it will enter the source of the image in the image tag.
I know there has to be a better way to do this.
Currently I have a php script which will generate a random image from a certain directory when called.
I have div's calling the background.php file in the stylesheet under the div's background setting
background:url(randomimagescript.php);
There are a lot of little div's on this page right now, all calling separate random image php scripts... is there a way I could use a variable when calling the file, so I can just use one script? I still need to have good styling control over the image, so i'm not sure if there is a better option than calling the script as a background image for a div.
If anyone has any ideas, let me know!
try this (it might not be optimal):
background:url("randomimagescript.php?folder=myfolder");
and in randomimagescript.php:
<?php
$folder = #_$REQUEST['folder'];
$url = "galleries/$folder/thumbs/image.jpg"; // ie, compose image
http_redirect($url); // go and find the image.
?>
It sounds a little crazy, but you could actually make your stylesheet be generated by PHP, and just fill in the blank, so to speak.
background:url(<? echo pickRandomImage(); ?>)
set the background for all divs once on the page using jquery
var image = <?echo randomimagescript.php?>
$("div").css('background', 'url('+ image+ ')');
Hey guys I'm wondering how I would be able to grab only the first image on a page. I want to echo it somewhere else possibly as a variable.
well I have not attempted this before, but I found a website that looks like it gives a pretty good solution. if you are trying to copy the first image from a URL. http://phpsnips.com/snippet.php?id=61
hope that helps. :)
You use PHP's DOMDocument class to grab the page's source, use an XPath query with DOMDocument to get the first img tag, then grab its src attribute.
http://php.net/manual/en/class.domdocument.php
You can then use that to save the url, or download the file.
I have some thumbnail images with its larger version.I placed the thumbnail images in a page.Now for link I just gave a link
<img src="thumbnail1.jpg>
but for this I have to make different pages for showing larger one.I want to give a link to show them in a single page.means whenever I will click the thumbnail it will open the larger one in a page with the same url but with its name like
imagegallery.php?news=images/largerimage1/13.jpg
imagegallery.php?news=images/largerimage1/14.jpg
so how to do that?
Pretty basic stuff, I suggest you get to read some PHP tutorials on the internet to get some knowledge on one thing and another.
The ?news= part in your URL is a parameter that can be read by PHP. This type is known as $_GET. To get this part you would need $_GET['news'] so if we'd use your first link and place this inside a script: echo $_GET['news']; the page would say images/largerimages1/13.jpg.
In order to get the image loaded on your website we need some simple steps, I'm changing the news parameter into image, that suits better for your script since it ain't news items:
<?php
// Define the path (used to see if an image exists)
$path = 'your/absolute/path/to/public_html/'; # or wwwroot or www folder
// First check if the parameter is not empty
if($_GET['image'] != "") {
// Then check if the file is valid
if(file_exists($path . $_GET['image'])) {
// If an image exists then display image
echo '<img src="'. $_GET['image'] . '" />;
}
}
?>
Below this script you can put all your thumbnails the way you want. Ofcourse, also for these thumbnails there are some automated options. But I strongly suggest you get a good look at the script above and some beginner PHP tutorials so you completely understand the example given. This still isn't the best method, but it's kicking you in the right direction.
if your imagegallery.php is in root of your domain, you can just add slash as a first char to links like this:
<img src="thumbnail1.jpg>
else you will have to write some php function which it returns BaseUrl of your web. Then it should looks like this:
<img src="thumbnail1.jpg>
maybe you can something like this,
Techincally, there is no thumbnail image, just a stretch version of the regular image
I don't understand which part you don't know how to do:
- the link part?
it should look like
<img src="thumbnail1.jpg>
- or the PHP part (the file called imagegallery.php)?