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'm attempting to generate a thumbnail for an image I have posted, but it seems when I call image_downsize, the index[0] actually prints an array as the URL. I'm a bit confused, so any help would be appreciated!

My code:

$wpUploadPath = wp_upload_dir();
$target_path = $wpUploadPath;
$filename = 'http://www.mysite.org/uploads/sampleFile.jpeg';

$fileNameFinal = pathinfo($filename);

$wp_filetype = wp_check_filetype($filename, null);

$attachment = array(
 'post_mime_type' => $wp_filetype['type'],
 'post_title' => $fileNameFinal['filename'],
 'post_content' => '',
 'post_status' => 'inherit'

$attach_id = wp_insert_attachment( $attachment, $target_path);

$upFile = image_downsize( $attach_id, 'thumbnail' );

Here is where I encounter the problem. If I print_r($upFile); I get:

Array ( 
    [0] => http://www.mysite.org/uploads/Array
    [1] => 0 
    [2] => 0 
    [3] =>

Is this normal? I can't seem to generate the thumbnail to update my user meta's with this.

Any help would be appreciated. Thanks!


share|improve this question
What is the value of $attach_id? – Sterling Hamilton Feb 14 '12 at 5:13
the value is 266 – tr3online Feb 14 '12 at 5:46
up vote 1 down vote accepted


(bool|array) False on failure, array on success. Array with image url, width, height, and whether is intermediate size, in that order is returned on success is returned. $is_intermediate is true if $url is a resized image, false if it is the original.

I am going to assume the array within the array part is completely odd.

So let's start working backwards...


Returns an array of key => value pairs containing path information on the currently configured uploads directory.


$upload_dir = wp_upload_dir();
echo $upload_dir['baseurl'];

I see that you have this instead:

$wpUploadPath = wp_upload_dir(); // this returns an array!
$target_path = $wpUploadPath; // now the target_path is an array?

That is setting the target path to an array instead of a string...

Also - target_path shouldn't be a full path..it should be the file name. The whole purpose of wp_upload_dir() is to determine the path.

The usage of wp_insert_attachement is as follows:

wp_insert_attachment( $attachment, $filename, $parent_post_id )

Notice how it says $filename.

Since you are passing $target_path as the second parameter into wp_insert_attachement() and that second parameter is intended to represent the filename, it makes the most sense that this is your problem.

share|improve this answer
Thanks. I think I was looking at the screen for too long! – tr3online Feb 14 '12 at 22:15

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.