damion Posted July 2, 2014 Share Posted July 2, 2014 (edited) PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 9 PHP Warning: file_exists() expects parameter 1 to be string, array given in /home/mysite/public_html/display.mysite.com/wp-content/themes/mytheme/form.php on line 13 I have a form that is having some issues and in the error log I see a bunch of these warnings. What is wrong with this?? I numbered the offending lines below (lines 9 & 13) Thanks for any help on this. function CheckExistance($VUrl) { /*9*/ if ( file_exists($VUrl) ) echo $VUrl; /*13*/ elseif ( file_exists(str_replace('www.display.mysite.com','www.display.com', $VUrl)) ) echo str_replace('www.display.mysite.com','www.mysite.com', $VUrl); else echo str_replace('www.mysite.com','www.display.mysite.com', $VUrl); } Edited July 2, 2014 by damion Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/ Share on other sites More sharing options...
requinix Posted July 2, 2014 Share Posted July 2, 2014 What's wrong is that $VUrl is an array and not the string you're expecting it to be. Start looking at whatever calls the CheckExistance function to see why that is and what you should do to fix it. Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483614 Share on other sites More sharing options...
damion Posted July 2, 2014 Author Share Posted July 2, 2014 It seems that CheckExistaisance is a thumbnail and the larger version image. It is an array, correct? <td><a href="<?php CheckExistance(get_field('image')); ?>" rel="lightbox" title="<?php echo the_title(); ?>"><img src="<?php CheckExistance(get_field('thumbnail')); ?>"></a></td> The million dollar question is, how do you fix that? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483615 Share on other sites More sharing options...
requinix Posted July 3, 2014 Share Posted July 3, 2014 get_field('thumbnail') returned an array. Apparently that's because the thumbnail is some sort of array "type". So that's the next place for you to start looking. Why is it an array? Have you considered outputting that value to see what it contains? Maybe it's supposed to be an array and you're supposed to get a specific value from it. Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483624 Share on other sites More sharing options...
damion Posted July 3, 2014 Author Share Posted July 3, 2014 (edited) How would I find it? I tried this, but nothing is showing on the page. print_r($get_field); Edited July 3, 2014 by damion Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483625 Share on other sites More sharing options...
requinix Posted July 3, 2014 Share Posted July 3, 2014 Probably because you don't have anything that sets that particular variable. There's a get_field('thumbnail') function call but there's no $get_field variable. Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483627 Share on other sites More sharing options...
maxxd Posted July 3, 2014 Share Posted July 3, 2014 Try assigning the return value of the function to a variable, then dump that. $thumb = get_field('thumbnail'); print("<pre>".print_r($thumb,true)."</pre>"); die(); That should show you what you're dealing with, assuming get_field() is returning anything. Quote Link to comment https://forums.phpfreaks.com/topic/289387-php-warning-file_exists-expects-parameter-1-to-be-string-array-given/#findComment-1483670 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.