• Hi everyone! I am uploading images to wordpress with the API using this endpoint: /wp-json/wp/v2/media but can I upload the image into a specific folder. For example wp-content/uploads/myfolder

    Thanks for the help!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can create your own API endpoint to achieve this

    Thread Starter gsosa2703

    (@gsosa2703)

    Hi thank u very much!

    I have another question, i have this function

    function upload_photo(){
    	
    	$desc = 'some description';
    	$file = 'url';
    	$file_array  = [ 'name' => wp_basename( $file ), 'tmp_name' => download_url( $file ) ];
    
    	// If error storing temporarily, return the error.
    	if ( is_wp_error( $file_array['tmp_name'] ) ) {
    		return $file_array['tmp_name'];
    	}
    	
    	// Do the validation and storage stuff.
    	$id = media_handle_sideload( $file_array, 0, $desc );
    		
    		// If error storing permanently, unlink.
    	if ( is_wp_error( $id ) ) {
    		@unlink( $file_array['tmp_name'] );
    		return $id;
    	}
    	
    }

    This function save an external url image inside wordpress and is working but it is saving the image in uploads/year folder but i need save the photo in a specific folder like, uploads/myfolder. How can i do it?

    Thanks again

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Upload image into specific folder’ is closed to new replies.