PHP Image rotation while uploading file from android -
i need image rotation while uploading android phone (can't test iphones because don't have one) so, post code below, not working @ least when upload image not in correct rotation appears sideways.
this php code:
$imgid = $_post['postid']; $newname = "$imgid.jpg"; $filename = $_files['filefield']['name']; $filepath = $_files['filefield']['tmp_name']; $exif = exif_read_data($_files['filefield']['tmp_name']); if (!empty($exif['orientation'])) { $imageresource = imagecreatefromjpeg($filepath); // provided image jpeg. use relevant function otherwise switch ($exif['orientation']) { case 3: $image = imagerotate($imageresource, 180, 0); break; case 6: $image = imagerotate($imageresource, -90, 0); break; case 8: $image = imagerotate($imageresource, 90, 0); break; default: $image = $imageresource; } } move_uploaded_file(imagejpeg($image, $filename, 90),"../pic/$newname");
my html form , javascript update 1 div image:
<script> function readurl(input) { if (input.files && input.files[0]) { var reader = new filereader(); reader.onload = function (e) { $('#blah') .attr('src', e.target.result) .width(200) .height(200); }; reader.readasdataurl(input.files[0]); } } </script> <form action='' enctype="multipart/form-data" method='post'> <input type='hidden' name='postid' value='<?php echo $row['postid'];?>'> <p><label>imagem</label><br /><input type="file" name="filefield" onchange="readurl(this);" /></p> <img id="blah" src="../pic/<?php echo $row['postid']; ?>.jpg" width="200" height="200" alt="your image" /> <p><input type='submit' name='submit' value='update'></p> </form>
would appreciated if can me this!!
Comments
Post a Comment