WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to store the local path to an uploaded file as a meta for a custom post type, using the following code:

$upload = wp_handle_upload ( $_FILES [WPSM_MAIL_META_ATTACHMENT], array ('test_form' => false ) );
if ((isset ( $upload ['error'] )) && ($upload ['error'] != 'Specified file failed upload test.')) {
    die ( $upload ['error'] );

} else {
    $path = $upload['file'];
    //$path = 'C:\Users\Brady\Music\Honour, Valour, Pride';
    update_post_meta ( 34, WPSM_MAIL_META_ATTACHMENT, $path );

With the $path = $upload['file'] call I get that $path contains "C:\xampp\htdocs\wordpress/wp-content/uploads/2011/12/ReSharper-6.1-License18.txt", but my *post_meta* row for this post has a empty *meta_value* column after the update. When I use the commented out assignment of a test literal to $path, the meta_value column is properly updated to the text path string.

I'm truly lost here. How can two string arguments to the same function call have such different effects?

share|improve this question

Check closely on your line:

With the $path = $upload['file'] call I get that $path contains "C:\xampp\htdocs\wordpress/wp-content/uploads/2011/12/ReSharper-6.1-License18.txt"

'\' changes to '/' just after the 'wordpress' i.e. \wordpress/, hence invalidating your path. But when you use a hard coded path (which is not invalid), you get the answer. Try fixing your path first.

share|improve this answer
It's only us that know it's a path. To WP it's just another string, and update_post_meta even does a stripslashes on it before doing the DB update, yet this still happens. I am debugging deeply now and will report back shortly, but thanks anyway. – ProfK Dec 18 '11 at 4:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.