This a variation on my Why doesn’t update_post_meta work for certain strings? question on WordPress Answers. I have brought it here because I suspect this is more likely a pure PHP issue than just a WordPress one.
My question is based around the following code:
$upload = wp_handle_upload ( $_FILES [WPSM_MAIL_META_ATTACHMENT], array ('test_form' => false ) );
$path = 'C:\xampp\htdocs\wordpress/wp-content/uploads/2011/12/ReSharper-6.1-License.txt';
var_dump($path);
$path = $upload['file'];
var_dump($path);
die();
update_post_meta ( 34, WPSM_MAIL_META_ATTACHMENT, $path );
The update_post_meta call updates the WPSM_MAIL_META_ATTACHMENT column in the WordPress database for post no. 34. The string literal assignment in line 2 gives $path exactly the same value as the array member assignment does in line 4, yet with the code as it is, the WPSM_MAIL_META_ATTACHMENT column is updated to an empty string. If I comment out line 4, therefore using only the literal assignment, the WPSM_MAIL_META_ATTACHMENT column is updated to the correct file path value.
I can only imagine that the two different strings assigned to $path differ in some way that is invisible to me with my very noob debugging tools var_dump and die. How can I go about diagnosing what is different between the two cases I describe above? Or, as a compromise, is there anything I can do to modify the $path = $upload['file'] assignment so that I get the same outcome as with the literal assignment?
The output in my browser window after this code executes is exactly as follows, reproduced as is, on a single line, for fidelity’s sake:
string(78) "C:\xampp\htdocs\wordpress/wp-content/uploads/2011/12/ReSharper-6.1-License.txt" string(78) "C:\xampp\htdocs\wordpress/wp-content/uploads/2011/12/ReSharper-6.1-License.txt"
This is hard to trace and require some source code digging :-
Turn out should be related to function
stripslahses_deep, andapply_filterIf you do this :-
I don’t have the definite conclusion,
likely is caused by slashes
To start a quick debug,
try to test value with