Jump to content

[SOLVED] if file doesn't exist create it... but even when it does, it's recreating it.


Recommended Posts

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

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

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.

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.

 

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.