Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-23-2005, 03:16 PM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
check for valid image via http

the file_exists() command works for local files, but i'm in search of a way to do this with a remote file.

i need to check if an image exists on an external server over http before i display it to the browser.

anyone know how i can achieve this?
__________________
Mike
sde is offline   Reply With Quote
Old 01-23-2005, 05:11 PM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
fopen.

PHP Code:
<?php
   $url 
'http://domain.com/foo.gif';

   
$fp = @fopen($url,'r');

   if (!
$fp) {
      echo 
"ERROR - URL {$url}, not accessable";
   }
   else {
      echo 
'YES';
   }

?>

..or if it's applicable have the script check every X minutes to see if the image is available and if so download it to the local server..

-r
idx is offline   Reply With Quote
Old 01-24-2005, 11:49 PM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
thanks a lot.
__________________
Mike
sde is offline   Reply With Quote
Old 01-25-2005, 12:27 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
unfortunately it is making my page lag a lot. i guess since the server is opening the image before the client is. this is just a temporary problem while i'm developing this web app anyway. later i'll have the images local.

is there any other way to check if the file is valid without opening it?
__________________
Mike
sde is offline   Reply With Quote
Old 01-25-2005, 03:16 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
now i'm trying to get the dimensions of a image remotely so i can resize the displayed image if it is too big.
__________________
Mike
sde is offline   Reply With Quote
Old 01-25-2005, 04:10 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
PHP Code:
<?
list($width$height) = getimagesize($url);
?>
i did not realize getimagesize() would work remotely. sweet!
__________________
Mike
sde is offline   Reply With Quote
Old 01-27-2005, 05:22 PM   #7 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
lol. That's cool.

The only other way might be to formulate some kind of http request (curl?) and check the response code. So the file is never downloaded...

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small modification needed on image flipping JavaScript Epsilon HTML, XML, Javascript, AJAX 0 08-31-2004 06:06 PM
Finding the size of an image? Epsilon PHP 2 06-22-2003 03:23 PM
I am a newb, how do you set multiple parts of an image as a link? I sniper baby HTML, XML, Javascript, AJAX 5 02-10-2003 07:40 PM
Stable Graphical FTP Client, HTML editor, & Image Manipulation for RedHat 7.3? Admin Linux / BSD / OS X 2 08-30-2002 05:55 PM


All times are GMT -8. The time now is 07:11 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting