我正在为我的网站创建一个文件上传脚本,并使用canvas.php缩小图像。上传工作正常,但缩放没有。我之前从未使用过这个,所以我希望这只是一个小错误。这是我的代码:
<?php
$newfilename = $id;
$extension = end(explode(".", $_FILES["file"]["name"]));
$path = "../posts/$type/";
//INSERT TO TABLE
if(mysqli_affected_rows($con)>0){
move_uploaded_file($_FILES["file"]["tmp_name"],"$path" . $newfilename . "." . $extension);
header("Location: ../dashboard.php?page=posts");
exit();
}
else{
header("Location: ../404.php");
}
?>
<?php
if($type == "photo"){
require_once "canvas.php";
$img = new canvas("$path" . $newfilename . "." . $extension);
$img
->resize("700")
->save("$path" . $newfilename . "." . $extension);
}
?>
这使用canvas.php(http://canvas.daviferreira.com/)