0

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?

1 Answer 1

1

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.

1
  • 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
    Commented Dec 18, 2011 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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