简体   繁体   中英

[php]Upload, edit and download image file within single use of form

Since some time i'm digging this topic, doing some research and it is not as easy as it seems to be. I want to achieve a script which will be loading an image file from client's pc, will edit it (add single letter in top left corner of an image) and save it as new file back on client's pc. So far i've learned how to create uploader and secure it from loading files other than images, how to open an image file to edit with GD extension. For now i have problems with: how to open uploaded file, i do not want to store a file in any other location but /tmp (file should be removed right after finishing whole operation). As i have no idea yet how to access uploaded file i'm unable to open it for editing with GD and save to file on client's device.

So far i ended up with something like this but i think it is not the way it should be written, what should i have to change to make it work?

<?php
    //basic info about uploaded file
    $origfilename = $_FILES['userfile']['name'];
    $type = $_FILES['userfile']['type'];
    $size = $_FILES['userfile']['size'];
    $tmpname = $_FILES['userfile']['tmp_name'];
    $errors = $_FILES['userfile']['error'];
    //opening uploaded file for editing and to store it on client's device 
    $imagesize = array getimagesize( string $filename [, array &$imageinfo ] ); //getting image dimensions
    $copyimage = bool imagecopy(int $src_w , int $src_h ); //copying image by received dimensions
    $exportimage = bool imagejpeg(resource $copyimage [, string $filename [, int $quality ]] ); //save copied image to .jpg file
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM