suttercain Posted October 13, 2007 Share Posted October 13, 2007 Hi guys, I am running this: <?php $imagePath = "images/4ndvddb/medium/".$row['cover_art']; if(!file_exists($ImagePath)){ $objResize = new RVJ_ImageResize("images/4ndvddb/".$row['cover_art']."", "images/4ndvddb/medium/".$row['cover_art']."", 'C', array('150', '250'), false); } ?> This SHOULD look for a file in the $imagePath and if it does not exist it creates an image. But, even if the image DOES exist it it still overwriting the old one, using up more resources... how should I correct the if statement to work right with the file diectory? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/ Share on other sites More sharing options...
pkSML Posted October 13, 2007 Share Posted October 13, 2007 Instead of checking the existence with file_exists, try getting the size of the file. It should return 0 for an error, which means it doesn't exist or exists with a size of 0 bytes. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368810 Share on other sites More sharing options...
suttercain Posted October 13, 2007 Author Share Posted October 13, 2007 When I tried echo filesize($ImagePath); no number was echoed. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368816 Share on other sites More sharing options...
suttercain Posted October 13, 2007 Author Share Posted October 13, 2007 I read that because my host has safemode on that even when using file_exists it will return false if safemode is on. I tried using the full path and it still comes back false. SC Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368827 Share on other sites More sharing options...
pkSML Posted October 13, 2007 Share Posted October 13, 2007 filesize() from PHP manual: Returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error. So turn on error_reporting on to 2047. If you get a warning, the file probably doesn't exist. FYI: file_exists from PHP manual: This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir. You should have access to your directories, which are specified in safe_mode_include_dir. So, file_exists should work for you. Check for errors in your file path. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368833 Share on other sites More sharing options...
suttercain Posted October 13, 2007 Author Share Posted October 13, 2007 I tried turning the error reporting on, and it didn't show any error, I also can manually check to see if the file exists both via the URL and the ftp, it exists, but both file_size and fileexists are not working. As far as safe mode, it said I should try the fill path, I did, but still no luck. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368846 Share on other sites More sharing options...
pkSML Posted October 14, 2007 Share Posted October 14, 2007 Hmmm... well... there's a hack. It's a little slower, but it'll work. Search fsockopen head request You'll find that if you do a head request and the HTTP status comes back 200, the file exists. If it comes back 404, well, then it isn't there. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368947 Share on other sites More sharing options...
corbin Posted October 14, 2007 Share Posted October 14, 2007 echo out $imagePath and see if it includes the file extension. Also, you're using a relative path, so make sure it's correct.... I might even try using an absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/73134-solved-if-file-doesnt-exist-create-it-but-even-when-it-does-its-recreating-it/#findComment-368950 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.