Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
file_exists() not working properly
Old 04-10-2010, 10:04 PM file_exists() not working properly
Skilled Talker

Posts: 90
Trades: 0
Hey all,

I'm trying to use file_exists() in order to recognize if an image exists according to the path given in a DB entry... and if not, it displays a default graphic.. but even with the image in the right place, it fails:

PHP Code:

$photo_directory    = "http://www.fasports.com/az/phx/images/champions/";
$default_photo        = "http://www.fasports.com/az/phx/images/champions/player_silhouette.jpg";

<? while($sat_wv_row mysql_fetch_array($saturdays_wv)){ ?>

    <td>

        <?php
        
            $photo_url    
$photo_directory.$sat_wv_row['photourl'];
        
            if(
file_exists($photo_url)) { } else { $photo_url $default_photo; }
        
        
?>
    
        <center>
        <a href="<? echo $photo_url?>" class="blue" title="View <? echo ($sat_wv_row['team']); ?>'s Team Photo" target="_blank">
        <img src="<? echo $photo_url?>" width="125"></a><br/>
        <b><? echo ($sat_wv_row['division']); ?></b><br/>
        <? echo ($sat_wv_row['team']); ?>
        </center>
        
    </td>
    
<? ?>
One example of a DB entry being spit out would have the $photo_url of:
"2010/winter/saturday_ev_competitive.jpg"

So if you combined the $photo_directory and $photo_url, you'd wind up with:
http://www.fasports.com/az/phx/image...ompetitive.jpg

If you try the link, you'll see the image does indeed exist.

Any ideas where I'm going wrong with my usage of file_exists()?

Thanks for the help!
msaz87 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-10-2010, 10:50 PM Re: file_exists() not working properly
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
file_exists looks for files on the local file system and will not work with a URL. If the files are on the local file system then you should modify your script to use file paths rather than urls.

If not you'll either need to use curl or manually make an http request for the file and check the status of the request. In both cases performance is going to depend on the response time of the remote server.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-11-2010, 12:44 AM Re: file_exists() not working properly
Skilled Talker

Posts: 90
Trades: 0
Got it -- made the change and it works great now... thanks for the help!
msaz87 is offline
Reply With Quote
View Public Profile
 
Old 04-13-2010, 07:30 AM Re: file_exists() not working properly
Novice Talker

Posts: 7
Trades: 0
thanks for info...
adedaza is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to file_exists() not working properly
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19465 seconds with 12 queries