Wednesday, 4 September 2013

PHP file upload image + Canvas php resize

PHP file upload image + Canvas php resize

I'm creating a file uploads script for my website and using canvas.php to
scale down the image. The upload works fine but the scaling doesn't. I've
never used this before so I'm hoping it's just a minor error. Here is my
code:
<?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);
}
?>

No comments:

Post a Comment