Jump to content

jpg doesnt load in php?


hix_boty

Recommended Posts

Hey ! Let me xplain what i have then my problem.
I have:
- one free web hosting server on wich i keep the images (.jpg)
- the images are grouped by name and month
         ( Example: http://example.com/john/november/pic01.jpg   &   http://example.com/mary/october/pic05.jpg )
- another free web hosting server on wich i keep my personal site that allows php .. BUT HAS SAFE MODE ON

Now i want to use a form like this to ask the user wich set of pictures he wants to see:
Name:
Month:

On submit will transmit the info to pics.php that i want to display all the pictures on that month ...
The server on wich i keep the php has safe mode enabled, so i guess wont display the image if they are from another server ?

My php code looks like this:
(I also tryed to make it display a message if no image exists on that month)



[code]<?php

$i=1;

//Code here for the images from 1 to 30, in all folders are max 31 pics so ill write the code below 31 times for all the pics that may exist in that folder, so nothing to do with scan the folder.

$pic31 = 'http://example.com/' . $_POST['name'] . '/' . $_POST['month'] . '/pic31.jpg';

if(file_exists($pic31)) 
{
echo '<img src="http://example.com/', $_POST['name'], '/', $_POST['month'], '/pic31.jpg"><br>';
   $i++;
}
else
{
echo ".";
}

//echo-ing these points i hope will look like loading :)

while($i<=1)
  {
  echo "No picture made this month";
  $i++;
  }

?>[/code]

So all i have to output is something like this ..

[code]
<html>
<head>
<title>Pictures</title>
</head>
<body>

<img src="http://example.com/john/january/pic01.jpg"><br>
<img src="http://example.com/john/january/pic02.jpg"><br>
<img src="http://example.com/john/january/pic03.jpg"><br>
// ....
<img src="http://example.com/john/january/pic31.jpg"><br>

</body>
</html>

[/code]

Even without the php code above ...
submit the form and I do a simple echo ...
[code]
<?php
echo '<img src="http://example.com/', $_POST['name'], '/', $_POST['month'], '/pic31.jpg"><br>';
?>
[/code]
The image wont show even thr html displays correct

The image doesnt loads ... because if i click properties on that X that shows instead of picture .. i copy the link and put it in my browser .. the image will show .. next time when i submit the form ... the image will show correctly as image is in temp folder.
This is very weird for me and i dont know what to do ????

Im very very new at this and ived tryed to make this work for 2 weeks, in wich i keept reading docs about php .. but didnt found any clue about a workaround.

This also applies to my script ... i know i migh didnt wrote it corectly ( example: " instead of ' and things like that )
So please tell me what is not corect here and how ill have to change it.
Its because the server has safe mode enabled? I also tryed on a server with safe mode off ... but still not working si my coding is not good :)

If this wont work on my server with safe mode enabled .. php to javascript would be a solution? Ived tryed a little of that ... but offcourse didnt worked.

Any sugestion will help.
Thanks alot
Link to comment
Share on other sites

[quote author=karthikeyan_coder link=topic=108267.msg435486#msg435486 date=1158412832]
Find:

[code]echo '<img src="http://example.com/', $_POST['name'], '/', $_POST['month'], '/pic31.jpg"><br>';[/code]

Replace with:

[code]$name = $_POST['name'];
$month = $_POST['month'];
echo '<img src="http://example.com/'.$name.'/'.$month.'/pic31.jpg"><br>';
[/code]

Thank you,
Karthi Keyan.
[/quote]

[code]<?php
echo '<img src="http://example.com/', $_POST['name'], '/', $_POST['month'], '/pic31.jpg"><br>';
?>[/code]

and

[code]<?php
$name = $_POST['name'];
$month = $_POST['month'];
echo '<img src="http://example.com/'.$name.'/'.$month.'/pic31.jpg"><br>';
?>[/code]

Produces the exact same output. Except you're creating copies of post indexes, which is bad.

[quote=manual]
[code]<?php
// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
?>[/code][/quote]

[hr]

As for the problem of TS, the only reason for this happening I can think of, is that the server hosting the images has some sort of 'hotlinking' protection.
Link to comment
Share on other sites


[quote=Sr. Helper]As for the problem of TS, the only reason for this happening I can think of, is that the server hosting the images has some sort of 'hotlinking' protection.[/quote]


The thing is that if i do a simple html like ...[code]
<html>
<head>
<title>Pictures</title>
</head>
<body>

<img src="http://example.com/john/january/pic01.jpg"><br>
<img src="http://example.com/john/january/pic02.jpg"><br>
<img src="http://example.com/john/january/pic03.jpg"><br>
// ....
<img src="http://example.com/john/january/pic31.jpg"><br>

</body>
</html>
[/code]

... the pictures will work just fine and load ( or javascript )

So the problem is still in php ... it wont load my pictures into the page unless i previously opened them
Something like ...
I open the url: http://example.com/john/january/pic31.jpg in my browser ... i see the picture and then if i try the php code, the picture will show just fine .. otherwise ... will show just the X that tells the picture doesnt exists.

And many thanks you for the correct way of ... [code]<?php
// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
?>[/code]
Link to comment
Share on other sites

[quote author=hix_boty link=topic=108267.msg435679#msg435679 date=1158435131]
So the problem is still in php ... it wont load my pictures into the page unless i previously opened them
[/quote]

Php doesn't load the images, the user's browser does. And it relies on the html for that.

You're saying the HTML produced is correct? Then php is not the problem.
Link to comment
Share on other sites

If the pictures show only after you've 'opened' them before, then you're seeing a cached version of the image from your temporary internet files.

If the html generated by your script is the same as an html page that will work [b]on the same server[/b], I'd be very surprised.

My bet is that either your php script is producing an incorrect image URL - which you can easily see by viewing the source of the generated html - or your image hosting service is blocking remote image loading.
Link to comment
Share on other sites

[quote author=AndyB link=topic=108267.msg435698#msg435698 date=1158437876]
If the pictures show only after you've 'opened' them before, then you're seeing a cached version of the image from your temporary internet files.

If the html generated by your script is the same as an html page that will work [b]on the same server[/b], I'd be very surprised.

My bet is that either your php script is producing an incorrect image URL - which you can easily see by viewing the source of the generated html - or your image hosting service is blocking remote image loading.
[/quote]

Only logical deduction: Deep linking (hotlinking) prevention.
Link to comment
Share on other sites

[quote]If the pictures show only after you've 'opened' them before, then you're seeing a cached version of the image from your temporary internet files.

If the html generated by your script is the same as an html page that will work on the same server, I'd be very surprised.

My bet is that either your php script is producing an incorrect image URL - which you can easily see by viewing the source of the generated html - or your image hosting service is blocking remote image loading.[/quote]

I just copied the html generated by my script, saved it as .html, upload it on the server .. and worked.
And after that .. i opened the .php script that was supposed to do the job ... worked just fine
As you sayd .. and as i mentioned ... it gets the images from the cache.

So my problem is that the php wont load the images from the internet.
There must be a coding mistake i think ... or deep linking (hotlinking) can prevent only php?

Lots of Thanks. :)
Link to comment
Share on other sites

[quote author=hix_boty link=topic=108267.msg435815#msg435815 date=1158451963]
As you sayd .. and as i mentioned ... it gets the images from the cache.
[/quote]

Where did you mention anything getting cached by anybody? Not in THIS thread you didn't.

[quote author=hix_boty link=topic=108267.msg435815#msg435815 date=1158451963]
So my problem is that the php wont load the images from the internet.
[/quote]

I don't like repeating myself, but: php doesn't load NATHING!!!!

Php outputs the html to the client, the client uses the src attribute of the img element to load the image. THE BROWSER decides to either load it from cache or re-download it. And even if it does, there is no guaranty it gets a fresh copy, as it can get a copy cached by a proxy it has to go through.


[quote author=hix_boty link=topic=108267.msg435815#msg435815 date=1158451963]
There must be a coding mistake i think ...
[/quote]

If what you've told us is true, there can not be. There, that was the last time I said that too.

[quote author=hix_boty link=topic=108267.msg435815#msg435815 date=1158451963]
or deep linking (hotlinking) can prevent only php?
[/quote]

Euh... English please?

As for verifying images are being read from browser cache:

IE: go to your Temporary Internet Files dir. All files should have an expiration datetime attribute.

FF: Page info > Tab media. All files have an expiration datetime attribute.

If the cachefile is valid (not expired) the browser WILL read it from cache.

As I explained, if there aren't any valid browser cachefiles you could still be looking at a proxy cached image.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.