Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP $_FILES Array Manipulation
    primarykey
    data
    text
    <p>I am using a form to upload an image. Upon image upload, we will be able to see the uploaded image. Then I used <code>JCrop</code> (<a href="http://deepliquid.com/content/Jcrop.html" rel="nofollow">http://deepliquid.com/content/Jcrop.html</a>) to allow cropping for this image. Let's assume I only care about <code>JPEG</code> images. I am then ready to submit the form.</p> <p>Upon form submission I will perform some image manipulation and crop the image. However I want to put the information for this cropped image back into the <code>$_FILES</code> array (this is a must). How would I go about manipulating this <code>$_FILES</code> array in a PHP script?</p> <p>Here is what I had attempted and it would not work.</p> <pre><code>$upload_dir = '/Users/user/Sites/tmp/'; $file_name = $_FILES['image']['name']; $file_name = "cropped_".$file_name; $tmp_name = $_FILES['image']['tmp_name']; $file_size = $_FILES['image']['size']; $src_file = imagecreatefromjpeg($tmp_name); list($width,$height) = getimagesize($tmp_name); // Creates cropped image $tmp = imagecreatetruecolor($_POST['w'], $_POST['h']); imagecopyresampled($tmp, $src_file, 0, 0, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $_POST['w'], $_POST['h']); $small_pic_file_path = $upload_dir.$file_name; imagejpeg($tmp,$small_pic_file_path,85); $message = "&lt;img src='http://localhost/~user/tmp/".$file_name."'&gt;"; $_FILES['image']['name'] = $file_name; $_FILES['image']['type'] = "image/jpeg"; // unlink($tmp_name); // if(!move_uploaded_file($upload_dir.$file_name, $tmp_name)) echo "Failure Moving Image"; $_FILES['image']['tmp_name'] = $upload_dir.$file_name; $_FILES['image']['error'] = 0; $sizes = getimagesize($upload_dir.$file_name); $_FILES['image']['size'] = ($sizes['0'] * $sizes['1']); </code></pre> <p>It is allowable to change this <code>$_FILES</code> array?</p>
    singulars
    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.
    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