PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old May 21st, 2002, 11:24 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
images

okay here's a stumper.. i want to be able to define whether or not an image exists, but NOT on my server. for example, if i am writing a script that would allow people to have their own icons (url to their own image) and if that image is dead then i want to replace it with my own image that says "this image is dead" or something like that.

any idea's how to achieve this? cause PHP won't read any image data for a file on an outside server as far as i can tell. plzkthx!

Reply With Quote
  #2  
Old May 21st, 2002, 11:55 PM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: images

Give this a try:

php Code:
Original - php Code
  1.  
  2. <?
  3. $theimage = @readfile("http://someserver.com/image.gif");
  4.    
  5. if($theimage == FALSE) {
  6.     echo "Bad image";
  7. }
  8.    
  9. ?>


It works for me


Reply With Quote
  #3  
Old May 22nd, 2002, 12:03 AM
svein svein is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 svein User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: images

if (getimagesize("http://www.server.com/images/image.gif")==NULL) {
echo "Bad image";
} else {
echo "Image OK.";
}


Check out http://www.php.net/manual/en/function.getimagesize.php for more info.

Reply With Quote
  #4  
Old May 22nd, 2002, 12:06 AM
svein svein is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 svein User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Code font

How do you get the font size smaller for your code in the posting above Matt ?

Reply With Quote
  #5  
Old May 22nd, 2002, 12:49 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

what the crap.. you guys make it so simple *cries* THX! although i can't actually try it until i get home but i'm sure it works

and svein, put your code inbetween tags: [ C O D E ] my code [ / C O D E ] no spaces

Reply With Quote
  #6  
Old May 22nd, 2002, 02:57 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

okay more help plz it's not quite working.. when i use the "readfile" it literally reads the file, and prints the garbage code on the screen even if i suppress error messages. not only that, it ignores the "if" statements it will either print the image or not from the "readfile" command alone but i don't even want it to print the image :-/

also is there a way to copy someones file from their own server to my own?

Reply With Quote
  #7  
Old May 22nd, 2002, 03:18 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: images

Ok, here we go..my bad on the readfile thing..it works if nothing else has been sent to the browser window...here is a tweaked version of svein's...this should do the trick:

php Code:
Original - php Code
  1.  
  2. <?
  3. echo "Some content....<BR>n";
  4.  
  5. $theimage = "http://www.google.com/logos/dilberttwo.gif";   
  6.  
  7. if (@getimagesize($theimage)==NULL) {
  8.     echo "Bad image";
  9. } else {
  10.     echo "<img src="$theimage" border=1>n";
  11. }
  12.  
  13. ?>



Reply With Quote
  #8  
Old May 22nd, 2002, 06:55 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

you're awsome matt $ svein, thank you

Reply With Quote
  #9  
Old May 23rd, 2002, 07:22 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

i'm noticing.. ya know how some images when dead will take a while to load? well when trying to execute a script using this dead img filter thing (discussed above), sometimes the script will just time out. how might i set a time limit on how long a certain function should attempt to execute before just continuing along with the rest of the script?

Reply With Quote
  #10  
Old May 24th, 2002, 04:51 AM
Smiley Smiley is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Australia
Posts: 30 Smiley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: images

That timeout value is probably dictated by the server that you are trying to read the file off.

If you were to try fopen on the url, you would either get back nothing after a while, or you would get back a 404 error page instead of the image.

Not sure if that bypasses the timeout or not though.

Reply With Quote
  #11  
Old May 25th, 2002, 01:05 AM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: images

To avoid this kind of timeout, I think I'd rather use client-side scripting (javascript). Instead of generating <img> tags, generate js code to check for the picture.

Ask me if U want more info, I don't have much time

Reply With Quote
  #12  
Old May 26th, 2002, 12:24 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

i would be interested in seeing the javascript code for something like that..

and also, i've got a problem that i'm sure has a simple solution but i just can't see it.. i need to create a loop, that loops 6 times, and prints a table of configurable rows and columns. right now i have it set into 2 loops, the first for rows and the second for columns, but that interferes with my wanting to insert seperate data into each table cell without the data repeating itself.. i'm calling for the data from a text file db so.. help on this too would be appreciated

Reply With Quote
  #13  
Old May 26th, 2002, 04:39 AM
D1NGO D1NGO is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Perth, Australia
Posts: 221 D1NGO User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: images

isnt that where you just put LIMIT 0,6 at the end of the SQL query?

Reply With Quote
  #14  
Old May 26th, 2002, 05:48 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

i don't use SQL.. i'm still on flatfile db's.. and PS ignore my above problem with the tables.

Reply With Quote
  #15  
Old May 29th, 2002, 09:55 AM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: images

i don't get it..

this works..
php Code:
Original - php Code
  1.  
  2. $theimage1 = "http://actual.uri.image";
  3.  
  4. if (@getimagesize($theimage1) == NULL)
  5. {
  6.     print("$deadImage");
  7. }
  8. else
  9. {
  10.     print("$theimage1");
  11. }


but this does not..
php Code:
Original - php Code
  1.