PHP upload issue with WordPress -> Want to upload to theme directory, but function is local to admin directory

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?

Read More

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!";
}

Related posts

Leave a Reply

2 comments