I have PHP code that generates HTML code which makes a grid of images. The images are taken from links that are generated for each new image, I also add 133x100 at the end of the image link to resize it on the page. My problem is that a seemingly random selection of images won't display, and I just get a broken image symbol. For example:
This is a link to an image that is generated on my page and is displayed.
This is a link to an image that will not be displayed.
I am only allowed to post 2 links, but removing the %20.%20/133x100 from the end of the last link will show what the picture should be.
Here is the part of the code for the image source:
function display_images(){
//This cycles through each image and displays it as HTML
while($row = $item->fetch()){
Echo "`<img src= '$link[Image_Link] . /133x100' />`"
}
}
It is then called here in a class which puts the images in a grid:
<ul class="rig columns-4">
<?php
display_images();
?>
</ul>
Seemingly about every 2/20 images won't work, and seeing all the links are in the same format, I don't understand why they won't work, and it just seems random.
EDIT: I have noticed that the links that work have 62fx62f at the end of them before the added %20.%20/133x100. If I add it to the raw link in the right place, it makes the image work. But using that generated link, the image still won't load on the page. So using a link with a working image will not work on the page. (This is the same with the raw link without %20.%20/133x100, that links to an image but also won't work on the website)
When visiting the links, the urls look like this:
http://www.example.com/image/randomcharacters%20.%20/133x100
The links work without the %20.%20 at the right dimensions, like so:
http://www.example.com/image/randomcharacters/133x100
This leads me to believe that it may work if you try using the following for the image source instead:
<img src= '$link[Image_Link]/133x100' />
The full code would look like this, for the while function:
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133x100' />";
}
I am not aware of steamcommunity much but from the looks of it, i think you should try this.
Instead of putting
. /133x100
Use
/133fx100f
So your URLs would be
while($row = $item->fetch()){
echo "<img src= '" . $link['Image_Link'] . "/133fx100f' />";
}
Just did some trial and error and found out. No explanations for this though!!
Related
All other parameters are echoing and the actual URL and the image is NOT displayed in the results page. I need a shortcut that will display the image itself.
Can I simply write:
$page_picture = ______( $some value['image.jpg'] );
So that $page_picture will display the image related to its associated URL?
All suggestions are welcome.
Just do this....
echo "<img src='".$page_picture."'>";
Assuming $page_picture is the url to your image, such as http://www.domain.com/img/blahblah.jpeg
If you wanna also link to the original image, when they click...
echo "<a href='".$page_picture."' target=_blank><img src='".$page_picture."'></a>";
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 standard text links which all say "Full View". When clicked these links send out php in this form: http://mysite.com/fullview.php?myimage=30
Basically there's thumbnailed images and text links that say full view. I'd like for fullview.php to capture the myimage variable, and display it as a full sized image. Meaning, a blank page (fullview.php) displaying the image. Sounds likes javascript to me.
How do you put the javascript into fullview.php to capture the variable and display it as a full sized image?
myimage=30 can be any number example: myimage=942
Thanks for any help, Darrell
If you just want to display a full-sized view of images, you may consider using a JavaScript image display library, such as fancybox. You can probably achieve what you want with the autoDimensions: true option, which is the default.
I think you are passing image id(myimage=30) to fullview.php. So you can simply get it with $_GET['myimage'] in fullview.php. Now you can use this imageid to get image and just display it with HTML <img> tag.
For example in fullview.php
if( isset( $_GET['myimage'] ) ) {
$imageid = $_GET['myimage'];
echo "<img src='/images/folder/path/" . $imageid . ".jpg' />";
}
I am trying to do the following; dynamically pick a server with the image on it, and then show said image in img src="". Yeah I know, I am horrible at explaining stuff like this but this should clear it up:
dl-main.php (on server0.domain.com)
$url = 'http://server2.domain.com/offerimage.php?f='.$_GET["f"];
header( 'Location: '.$url ) ;
offerimage.php (on server2.domain.com)
//Lots of link-protection stuff here
$f = "/".$_GET["f"];
$url = 'http://server2.domain.com'.$uri_prefix.$m.'/'.$t_hex.$f;
echo' <img src="'.$url.'"></img> ';
dl.php (on many other servers)
img src="http://server0.domain.com/dl-main.php?f=lalala.gif"
So it pretty much goes like this: Random person adds img src directing to dl-main.php?f=filename on server0. server0 then decides which server will provide the image. In the above example I am using only one server; server2
Now I simply want dl.php to show the photo hosted on server2.domain.com .
As it stands when I directly visit dl-main.php it succesfully redirects me to dl.php, which then succesfully shows me the image I requested. But when I use dl-main.php in a img src it doesn't show the image. I didn't expect it to work but it was worth a shot, but now I don't know what to do anymore :o
I hope this failed attempt is a good example of what I'm trying to accomplish here.
Thanks!
Here's the problem. You call image from server0 using:
<img src="http://server0.whatever/dl-main.php?f=thatimage.something" />
Where the dl-main.php code redirects to server2. Here, you do:
echo' <img src="'.$url.'"></img> ';
So basically the original img tag would get another img tag instead of the image data. That's why the browser can't render the image. You should echo the content of the image instead of an img tag.
Try using your browser's developer tools and check the request to server2 to verify my guess.
It can't work, your second script (offerimage) is producing text/plain, you should produce image/...in order to use img
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)?