0

I am having problems with both is_file() and file_exists(), i am trying to verify a featured image exists in the wp uploads folder....both output sets of characters and create multiple errors for each thumbnail size

fopen(http://www.xxx.gf/wp-content/uploads/2014/09/1-150x150.jpg): failed to open stream: HTTP wrapper does not support writeable connections in /home/tserv/public_html/wp-includes/class-wp-image-editor.php on line 396

This is odd because i am passing a correct server path to both functions and the functions works for files outside the uploads folder. Also the filename is 1.jpg and its appending - 150x150 and a few other sizes which are the thumbnail sizes for wordpress.

update: server path is being passed: e.g. home/user/etc.., the error is saying fopen... but im not calling fopen directly nor passing a url to file_exists, is_file.

Since starting this i realize i'm mad for trying to verify it like this when i can check it using wp_functions but i would like to figure out why this is happening!

php code

if($x= is_file($upload_path.$filename) )

server- linux debian wheezy vps 
open_basedir= None
safemode- off
folder permissions - 777 (temp)
Anoop Asok
  • 1,311
  • 1
  • 8
  • 20
David
  • 5,897
  • 3
  • 24
  • 43
  • What error do you get using `file_exists();` ? – Edward Sep 16 '14 at 23:57
  • Can you try checking if the file exist directly? i.e. not using a wrapper: `file_exists('../path/to/file.jpg');` What does that return? – Edward Sep 17 '14 at 00:11
  • still the same, it works with files but fails for images in the uploads folder... – David Sep 17 '14 at 00:23
  • I can't see why this would fail, can you try getting the file size `getimagesize('../path/to/file.jpg');` as per this question http://stackoverflow.com/questions/7991425/php-how-to-check-if-image-file-exists Please make sure you are using physical paths (not a URL) – Edward Sep 17 '14 at 00:33
  • get_image_size works ok as well....anyway i have this working now, i deleted that file, reset folder permissions to 744 and restarted php fpm. ill try and recreate it some other time, the image was uploaded using base64 and decoded so maybe something got corrupted along the way, still that error should not have been appearing even if image path is wrong, img is corrupt, etc – David Sep 17 '14 at 00:52

1 Answers1

0

You can't open the file using fopen using http and expect to write to the file. You will want to use fopen and specify the second option as "r" for read only or you can keep using this code but actually access it using the servers path and not http:// . You can also use file get contents.

try using http://codex.wordpress.org/Function_Reference/wp_upload_dir when accessing the upload

$upload_dir = wp_upload_dir(); // Array of key => value pairs
//base dir
$base_dir = $upload_dir['basedir'];
michael.schuett
  • 4,248
  • 4
  • 28
  • 39