I am creating a custom image upload area in WordPress, but I am getting a lot of difficulty coping with the look once it has been submitted. Additionally towards the upload, I have to re-size the look to utilize a thumbnail. Each time I attempt to utilize the submitted image, I recieve a mistake related to being not able to obtain the file (despite the fact that I'm able to notice inside a browser and it is clearly within the directory). Images are 666 automatically when submitted, but I have also attempted adjusting one at 777 with similar results. The re-size function is known as by itself following the image is submitted. Here's among the attempts I made:

function resize_author_picture($filename) {
  $filename = $_POST['file'];
  $file = fopen($filename, 'r');
  $data = fread($file);
  $dimensions = getimagesize($filename);
  $dir = dirname($filename);
  $crop = wp_crop_image( $data, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $dir."/image.jpg" );

  die( "crop: ".var_dump($crop)." file: ".$filename." path: ".$dir."/image.jpg" );

Here' used fopen() like a second attempt once supplying only the image's path did not work. This is actually the previous attempt:

function resize_author_picture($file) {
 $file = $_POST['file'];
 $dimensions = getimagesize($file);
 $dir = dirname($file);
 $crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280, null, $dir."/image.jpg" );
 die( "crop: ".var_dump($crop)." file: ".$file." path: ".$dir."/image.jpg" );

Both return a Wordpress error object along wrinkles:

string(123) "File <http://site.local/wp-content/uploads/2010/09/squares-wide.jpeg> doesn't exist?"

Drained of ideas, any input is appreciated!

Should you used the inline upload feature, the picture come in the /wordpress-content/uploads folder, unless of course you've specified another folder around the Miscellaneous admin panel.

Ensure that you haven't transformed the upload directory location.

Try uploading while using Wordpress Publish tools to make sure that your configurations are correct. Then move ahead the debugging code - when you ruled the most fundamental.

Doubt you'll still need a solution, because this real question is quite old, but here you go for future reference:

The mistake your getting is really a return of wp_load_image which is often used by wp_crop_image. wp_load_image uses the php function file_exists, which must be given the file's path with no domain.


$crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280,
        null, "wp-content/uploads/2010/09/squares-wide.jpeg" );

might have labored.

An aside wp_upload_bits doesn't only upload the file(s) for you personally additionally, it returns the Link to the submitted file.

Should you call wp_upload_bits like so (where "file" may be the title from the form's input):

if ($_FILES["file"]["name"]!="") {
    $uploaded_file = wp_upload_bits($_FILES["file"]["name"], null,

Hence $uploaded_file['url'] is the same as $dir."/image.jpg". Within the above crop, you might have used a substring of $uploaded_file['url'].

Concrete example:

With http://site.local/wp-content/uploads/2010/09/squares-wide.jpeg this works:

$dir = dirname($file);
$dir_substr = substr($dir, 18)
$crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280,
        null, $dir."/squares-wide.jpeg" );

Obviously additionally you want the filename to become dynamic, so I'd call wp_uload_bits as suggested above (when not from a form area, but a Wordpress Custom area refer to it as when you are doing now, the key part is $uploaded_file = wp_upload_bits(...) in order to save the return of wp_upload_bits inside a variable later) after which do

$file_uri = substr($uploaded_file['url'], 18);
$crop = wp_crop_image( $file, $dimensions[0], $dimensions[1], 0, 0, 250, 280,
        null, $file_uri );