|
-
May 6th, 2007, 07:19 AM
#1
Thread Starter
Hyperactive Member
Check to see if file exists?
I'm using a simple method to display 'avatars' on my page. Rather than uploading a users picture, I simply use the URL they provide. To make sure the link is a picture I check from the right and up to the first '.' encountered. If I get 'jpg/jpeg/bmp/png/gif' returned then the link is a picture.
However what I would also like to do is, if the link no longer exists or cannot be found, show a generic picture.
Any ideas on how to do this bit?
-
May 6th, 2007, 07:31 AM
#2
Re: Check to see if file exists?
What you could do is download the file from the URL they provide and load it using the GD library (if you have that installed). Using this method, you can both check that it exists and that it is a valid image without having to resort to parsing the URL (which could fail in valid circumstances; for example, if the remote host uses URL rewriting).
You can then display the local downloaded copy of the image, which avoids bandwidth theft.
A similar method is employed on this forum. If you edit your avatar you will notice an option to upload a file from a remote URL.
-
May 6th, 2007, 08:00 AM
#3
Thread Starter
Hyperactive Member
Re: Check to see if file exists?
The reason I didn't want to download files from URLs provided is memory issues. Should I be concerned by this?
-
May 6th, 2007, 08:46 PM
#4
Re: Check to see if file exists?
My usual boring signature: Something
-
May 6th, 2007, 09:33 PM
#5
Re: Check to see if file exists?
 Originally Posted by wwwfilmfilercom
The reason I didn't want to download files from URLs provided is memory issues. Should I be concerned by this?
Memory, or storage space?
If it's storage space, then impose a file size limit.
 Originally Posted by dclamp
try file_exists($file);
That only works for local files and some URL wrappers, of which HTTP isn't one of them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|