【发布时间】:2017-05-08 13:24:52
【问题描述】:
我正在为我的 php 表单而苦苦挣扎。我想通过输入捕获功能上传图像。但是在 iOS 设备上捕获 img 后图像会旋转。我发现了大量关于 exif 的文章,但对我没有任何帮助。所以我将我的代码粘贴在下面,我想寻求帮助如何实现代码以旋转到其余代码。 (我不知道该怎么做。)谢谢兄弟的帮助。或者有什么建议? 实现代码:
fileReader.onloadend = function() {
var exif = EXIF.readFromBinaryFile(new BinaryFile(this.result));
switch(exif.Orientation){
case 8:
ctx.rotate(90*Math.PI/180);
break;
case 3:
ctx.rotate(180*Math.PI/180);
break;
case 6:
ctx.rotate(-90*Math.PI/180);
break;
}};
剩下的:
if (isset($_POST['submit'])) {
if (empty($_POST['title']) or empty($_POST['shop']) or empty($_FILES['image']) or empty($_POST['price'])) {
echo "All fields must be filled";
}
else {
$userID = $_POST['userID'];
$title = $_POST['title'];
$price = $_POST['price'];
$price_before = $_POST['price_before'];
$town = $_POST['town'];
$shop = $_POST['shop'];
if(empty($_POST['price_before'])){
$price_before = null;
}
if(empty($_POST['cut'])){
$pcut = null;
}
if (isset($_FILES['image'])) {
$errors = array();
$file_name = $_FILES['image']['name'];
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_type = $_FILES['image']['type'];
$file_ext = strtolower(end(explode('.', $_FILES['image']['name'])));
$expensions = array("jpeg", "jpg", "png");
if (in_array($file_ext, $expensions) === false) {
$errors[] = "extension not allowed, please choose a JPEG or PNG file.";
}
if ($file_size > 8097152) {
$errors[] = 'File size must be less than 8 MB';
}
if (empty($errors) == true) {
session_start();
$hour = date("H");
$min = date("i");
$sec = date("s");
$day = date("d");
$month = date("m");
$year = date("Y");
$url = "../pic/".$file_name.".".$file_ext;
$file_name = md5(uniqid());
move_uploaded_file($file_tmp, "../pic/".$file_name.".".$file_ext);
$upload = "INSERT INTO item (userID, title, price, price_before, town, shop, img_name, img_ext, hour, min, sec, day, month, year) VALUES ('$userID', '$title', '$price',' $price_before', '$town', '$shop', '$file_name', '$file_ext', '$hour', '$min', '$sec', '$day', '$month', '$year' )";
$result = $conn -> query($upload);
echo '<div style=width:100%;height:100%;display:flex;margin:0;>
<div style=width:auto;height:auto%;vertical-align:middle;margin:auto;><div class="cssload-spin-box"></div></div></div>';
header('Refresh: 2; URL = ../index.php');
} else {
print_r($errors);
}
}
}
}
【问题讨论】: