Jump to content


Photo

jpg doesnt load in php?


  • Please log in to reply
9 replies to this topic

#1 hix_boty

hix_boty
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 September 2006 - 06:49 AM

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/j...mber/pic01.jpg   &   http://example.com/m...tober/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)



<?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++;
  }

?>

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

<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>


Even without the php code above ...
submit the form and I do a simple echo ...
<?php
echo '<img src="http://example.com/', $_POST['name'], '/', $_POST['month'], '/pic31.jpg"><br>';
?>
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

#2 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 16 September 2006 - 01:20 PM

Find:

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

Replace with:

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

Thank you,
Karthi Keyan.
www.karthi.us

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 01:52 PM

Find:

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

Replace with:

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

Thank you,
Karthi Keyan.


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

and

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

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

<?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";
?>


 

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.


#4 hix_boty

hix_boty
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 September 2006 - 07:32 PM


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.



The thing is that if i do a simple html like ...
<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>

... 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/j...nuary/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 ...
<?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";
?>


#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 07:43 PM

So the problem is still in php ... it wont load my pictures into the page unless i previously opened them


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.

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 08:17 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#7 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 08:30 PM

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.


Only logical deduction: Deep linking (hotlinking) prevention.

#8 hix_boty

hix_boty
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 September 2006 - 12:12 AM

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.


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. :)

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 12:20 AM

I don't have any of your images cached.  Post the full URL to any one of your images. I'm skeptical about this problem.
Legend has it that reading the manual never killed anyone.
My site

#10 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 17 September 2006 - 01:06 AM

As you sayd .. and as i mentioned ... it gets the images from the cache.


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

So my problem is that the php wont load the images from the internet.


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.


There must be a coding mistake i think ...


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

or deep linking (hotlinking) can prevent only php?


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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users