I am trying to write a upload function in the WP functions.php. It works great, uploading the file to wp-admin, I want it to go into the themes directory – which I can access with get_bloginfo… but that is an absoluter address.
Is there a way to upload a file to a directory that is in the same site, but not the same directory?
The file structure is like this
wp-admin
wp-content
themes
Mytheme
the function runs in wp-admin, but I want it to go into my themes.
$target_path = get_bloginfo('template_url');//NOT WORKING ABSOLUTE PATH
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
echo(">> " . $target_path . " <<");
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
Use get_bloginfo() with the
stylesheet_directory
parameters.See: http://codex.wordpress.org/Function_Reference/get_bloginfo#Template_Directory for reference.
Try to modify your code like this:
just an addition: most of the time yous should store your uploaded files in the configured upload folder – get it with http://codex.wordpress.org/Function_Reference/wp_upload_dir