Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom image upload field in WordPress
    primarykey
    data
    text
    <p>I'm developing a custom image upload field in WordPress, but I'm having a ton of difficulty dealing with the image once it's been uploaded. In addition to the upload, I need to resize the image to use a thumbnail. Every time I try to work with the uploaded image, I get an error to do with being unable to find the file (even though I can view it in a browser and it's clearly in the directory). Images are 666 by default when uploaded, but I've also tried manipulating one at 777 with the same results. The resize function is called on its own after the image is uploaded. Here's one of the attempts I made:</p> <pre><code>function resize_author_picture($filename) { $filename = $_POST['file']; $file = fopen($filename, 'r'); $data = fread($file); fclose($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" ); } </code></pre> <p>Here I used fopen() as a second attempt once providing just the image's path didn't work. Here is the previous attempt:</p> <pre><code>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" ); } </code></pre> <p>Both return a WP error object along these lines:</p> <pre><code>string(123) "File &lt;http://site.local/wp-content/uploads/2010/09/squares-wide.jpeg&gt; doesn't exist?" </code></pre> <p>Running out of ideas, any input is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload