How to move a object(GdImage) to a specific folder? - php

I'm working on a image converter that convert jpg and png to webp and webp to jpg and png and i've been trying to make that the converted files go to a specific folder instead of my working folder but it doesn't go on my convert forlder
here's my code
<?php
require "db.php";
$pdo = new \PDO(DSN, USER, PASS);
if (!empty($_FILES['files']['name'][0])) {
$files = $_FILES['files'];
$fileName = $_POST['name'];
$fileTag = $_POST['tag'];
$fileDescription = $_POST['description'];
$convert = $_POST['convert'];
$uploaded = array();
$failed = array();
$allowed = array('jpg', 'jpeg', 'png', 'webp');
foreach ($files['name'] as $position => $file_name) {
$file_tmp = $files['tmp_name'][$position];
$file_size = $files['size'][$position];
$file_error = $files['error'][$position];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
if (in_array($file_ext, $allowed)) {
if ($file_error === 0) {
if ($file_size <= 2097152) /* 2mb */ {
$file_name_new = uniqid('IMG-', true) . '.' . $file_ext;
$file_destination = 'uploads/' . $file_name_new;
if (move_uploaded_file($file_tmp, $file_destination)) {
$uploaded[$position] = $file_destination;
$query = "INSERT INTO images(name, tag, description, images) VALUES (:name, :tag, :description,:images)";
$statement = $pdo->prepare($query);
$statement->bindValue(':name', $fileName, \PDO::PARAM_STR);
$statement->bindValue(':tag', $fileTag, \PDO::PARAM_STR);
$statement->bindValue(':description', $fileDescription, \PDO::PARAM_STR);
$statement->bindValue(':images', $file_name_new, \PDO::PARAM_STR);
$statement->execute();
$upload = $statement->fetchAll();
} else {
$failed[$position] = "[{$file_name}] failed to upload.";
}
} else {
$failed[$position] = "[{$file_name}] is too large.";
}
} else {
$failed[$position] = "[{$file_name}] failed to upload {$file_error}.";
}
} else {
$failed[$position] = "[{$file_name}] file extension '{$file_ext}' is not allowed.";
}
}
if (!empty($uploaded)) {
print_r($uploaded);
}
if (!empty($failed)) {
print_r($failed);
}
} else {
echo 'no files';
}
if (exif_imagetype($file_destination) == IMAGETYPE_PNG && $convert ==='webp') {
$image = imagecreatefrompng($file_destination);
imagewebp($image, str_replace('png', 'webp', $file_name_new));
move_uploaded_file($file_destination, 'convert/');
} elseif (exif_imagetype($file_destination) == IMAGETYPE_JPEG && $convert ==='webp') {
$image = imagecreatefromjpeg($file_destination);
imagewebp($image, str_replace('jpg', 'webp', $file_name_new));
move_uploaded_file($file_tmp, 'convert/');
} elseif (exif_imagetype($file_destination) == IMAGETYPE_WEBP && $convert ==='png') {
$image = imagecreatefromwebp($file_destination);
imagepng($image, str_replace('webp', 'png', $file_name_new));
move_uploaded_file($file_tmp, 'convert/');
}elseif (exif_imagetype($file_destination) == IMAGETYPE_WEBP && $convert ==='jpg') {
$image = imagecreatefromwebp($file_destination);
imagepng($image, str_replace('webp', 'jpg', $file_name_new));
move_uploaded_file($file_tmp, 'convert/');
}else {
echo "can't convert it";
}var_dump($image);
I tried changing the variable in the move_uploaded_file but still won't let me

Related

Warning: exif_imagetype(IMG-635b877fbb2892.73329302.jpg): Failed to open stream: No such file or directory

I'm making an image converter and I wanted to make a condition to check the file extension et change it to another one, ex: if it's jpg/png change it to webp
I keep having the warning on the line 85, 90 and 95
<?php
require "db.php";
$pdo = new \PDO(DSN, USER, PASS);
if (!empty($_FILES['files']['name'][0])) {
$files = $_FILES['files'];
$fileName = $_POST['name'];
$fileTag = $_POST['tag'];
$fileDescription = $_POST['description'];
$uploaded = array();
$failed = array();
$allowed = array('jpg', 'jpeg', 'png', 'webp');
foreach ($files['name'] as $position => $file_name) {
$file_tmp = $files['tmp_name'][$position];
$file_size = $files['size'][$position];
$file_error = $files['error'][$position];
$file_ext = explode('.', $file_name);
$file_ext = strtolower(end($file_ext));
if (in_array($file_ext, $allowed)) {
if ($file_error === 0) {
if ($file_size <= 2097152) /* 2mb */ {
$file_name_new = uniqid('IMG-', true) . '.' . $file_ext;
$file_destination = 'uploads/' . $file_name_new;
if (move_uploaded_file($file_tmp, $file_destination)) {
$uploaded[$position] = $file_destination;
$query = "INSERT INTO images(name, tag, description, images) VALUES (:name, :tag, :description,:images)";
$statement = $pdo->prepare($query);
$statement->bindValue(':name', $fileName, \PDO::PARAM_STR);
$statement->bindValue(':tag', $fileTag, \PDO::PARAM_STR);
$statement->bindValue(':description', $fileDescription, \PDO::PARAM_STR);
$statement->bindValue(':images', $file_name_new, \PDO::PARAM_STR);
$statement->execute();
$upload = $statement->fetchAll();
} else {
$failed[$position] = "[{$file_name}] failed to upload.";
}
} else {
$failed[$position] = "[{$file_name}] is too large.";
}
} else {
$failed[$position] = "[{$file_name}] failed to upload {$file_error}.";
}
} else {
$failed[$position] = "[{$file_name}] file extension '{$file_ext}' is not allowed.";
}
}
if (!empty($uploaded)) {
print_r($uploaded);
}
if (!empty($failed)) {
print_r($failed);
}
} else {
echo 'no files';
}/*
$image = imagecreatefromjpeg($file_destination);
imagewebp($image, str_replace('jpg', 'webp', $file_name_new));
$image = imagecreatefrompng($file_destination);
imagewebp($image, str_replace('png', 'webp', $file_name_new));
$image = imagecreatefromwebp($file_destination);
imagepng($image, str_replace('webp', 'png', $file_name_new));
$image = imagecreatefromwebp($file_destination);
imagejpeg($image, str_replace('webp', 'jpg', $file_name_new));
*/
if (exif_imagetype($file_name_new) == IMAGETYPE_PNG) {
$image = imagecreatefrompng($file_destination);
imagewebp($image, str_replace('png', 'webp', $file_name_new));
} elseif (exif_imagetype($file_name_new) == IMAGETYPE_JPEG) {
$image = imagecreatefromjpeg($file_destination);
imagewebp($image, str_replace('jpg', 'webp', $file_name_new));
} elseif (exif_imagetype($file_name_new) == IMAGETYPE_WEBP) {
$image = imagecreatefromwebp($file_destination);
imagepng($image, str_replace('webp', 'png', $file_name_new));
}
It's not the best but i'll be working on making it better once the warning is gone
I tried to change the condition but kept having this warning
It also appeared when I made the converted file go to a folder

File name too long while uploading image in database

I have written a line of codes to upload an image in the database, however, trying to upload image gives me this error
File name too long
Following is my code to upload an image to database:
if($_SERVER['REQUEST_METHOD']=="POST")
{
$pid = rand(1000,9000);
$title = $_POST['title'];
$descpt = $_POST['description'];
$push = isset($_POST['send_push']) ? $_POST['send_push'] : "";
$feature_image = array();
$fy = $_POST['fy'];
if(empty($title) || empty($descpt) || empty($fy))
{
array_push($this->errors, MEND_FIELD_ERROR);
return;
}
if(!empty($_FILES['feature_image']['name'][0]))
{
$image = $_FILES['feature_image'];
$allowed_ext = array('jpeg','jpg','png','pdf','docx');
$allowed_size = 20000000;
foreach($image['name'] as $pos=>$image_name)
{
$dir = "./cdn/uploads/notice/".$title;
$tmp = $image['tmp_name'][$pos];
$img_size = $image['size'][$pos];
$img_error = $image['error'][$pos];
$img_ext = explode('.', $image_name);
$img_name = $img_ext[0];
$img_ext = strtolower(end($img_ext));
if(in_array($img_ext, $allowed_ext))
{
if($img_size <= $allowed_size)
{
if(!file_exists($dir))
{
mkdir($dir);
}
$image_new_name = $img_name.'$$'.uniqid('', true).'.'.$img_ext;
$upload_destination = $dir.'/'.$image_new_name;
if(move_uploaded_file($tmp, $upload_destination))
{
array_push($feature_image, $image_new_name);
}
else
{
array_push($this->errors, $img_error);
return;
}
}
}
else
{
array_push($this->errors, $img_ext.' is not an allowed file extension.');
return;
}
}
}
$s_feature_image = json_encode($feature_image, JSON_UNESCAPED_UNICODE);
$statement = $this->db->prepare("INSERT INTO `notice` (`pid`,`title`,`descpt`,`date`,`photo`,`fy`)
VALUES (?,?,?,?,?,?)");
if($statement->execute([$pid,$title,$descpt,DAT, $s_feature_image, $fy]))
{
if($push == "checked")
{
$descpt = strip_tags($descpt);
$tek = array("message"=>$descpt,"title"=>$title);
$tokens = $this->getTokens();
$this->push_notification($tokens,$tek);
}
ExitThis::send_to(URL.'notice?id='.$pid);
}
else
{
array_push($this->errors, DATABASE_ERROR);
return;
}
}
Is it because of permission issue or something else? If so, what is causing me this problem and how do I fix this?
this is how I upload the file into the server and save the file name + extension into the database.
<?php
include 'connection.php';
$id = $_POST['id'];
$imgFile = $_FILES['photo']['name'];
$tmp_dir = $_FILES['photo']['tmp_name'];
$imgSize = $_FILES['photo']['size'];
$folder = 'images/'; // upload directory
$imgExt = strtolower(pathinfo($imgFile, PATHINFO_EXTENSION)); // get image extension
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
// rename uploading image
$img = rand(1000, 1000000) . "." . $imgExt;
// allow valid image file formats
if (in_array($imgExt, $valid_extensions)) {
// Check file size '5MB'
if ($imgSize < 5000000) {
move_uploaded_file($tmp_dir, $folder . $img);
} else {
$errMSG = "Sorry, your file is too large.";
}
} else {
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
$query = mysqli_query($con, "UPDATE `profile` SET `photo` = '$img' WHERE `id` = '$id'");
if ($query) {
echo "<script>alert('Profile Updated'); window.location ='index.php?data=profile' </script>";
} else {
echo "<script>alert('Failed'); window.location ='index.php?data=profile' </script>";
}
?>
Hope this helps.
Cheers.

Unable to reduce image file size in php while uploading

I following code can upload multiple image and rename them while upload and it works fine.Then i tried to implement image compress but this doesn't work, can someone help me to solve this issue.
Without compress method
if (!empty($_POST)) {
$newname = md5(rand() * time());
if (isset($_FILES['files'])) {
$uploadedFiles = array();
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$errors = array();
$file_name = md5(uniqid("") . time());
$file_size = $_FILES['files']['size'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
$file_type = $_FILES['files']['type'][$key];
if ($file_type == "image/gif") {
$sExt = ".gif";
} elseif ($file_type == "image/jpeg" || $file_type == "image/pjpeg") {
$sExt = ".jpg";
} elseif ($file_type == "image/png" || $file_type == "image/x-png") {
$sExt = ".png";
}
if (!in_array($sExt, array('.gif', '.jpg', '.png'))) {
$errors[] = "Image types alowed are (.gif, .jpg, .png) only!";
}
if ($file_size > 2097152000) {
$errors[] = 'File size must be less than 2 MB';
}
$desired_dir = "upload/";
if (empty($errors)) {
if (is_dir($desired_dir) == false) {
mkdir("$desired_dir", 0700);
}
if (move_uploaded_file($file_tmp, "$desired_dir/" . $file_name . $sExt)) {
$uploadedFiles[$key] = array($file_name . $sExt, 1);
} else {
echo "Couldn't upload file " . $_FILES['files']['name'][$key];
$uploadedFiles[$key] = array($_FILES['files']['name'][$key], 0);
}
} else {
}
}
foreach ($uploadedFiles as $key => $row) {
if (!empty($row[1])) {
$codestr = '$file' . ($key + 1) . ' = $row[0];';
eval($codestr);
} else {
$codestr = '$file' . ($key + 1) . ' = NULL;';
eval($codestr);
}
}
}
With compress method
if (!empty($_POST)) {
$newname = md5(rand() * time());
if (isset($_FILES['files'])) {
$uploadedFiles = array();
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$errors = array();
$file_name = md5(uniqid("") . time());
$file_size = $_FILES['files']['size'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
$file_type = $_FILES['files']['type'][$key];
if ($file_type == "image/gif") {
$sExt = ".gif";
} elseif ($file_type == "image/jpeg" || $file_type == "image/pjpeg") {
$sExt = ".jpg";
} elseif ($file_type == "image/png" || $file_type == "image/x-png") {
$sExt = ".png";
}
if (!in_array($sExt, array('.gif', '.jpg', '.png'))) {
$errors[] = "Image types alowed are (.gif, .jpg, .png) only!";
}
if ($file_size > 2097152000) {
$errors[] = 'File size must be less than 2 MB';
}
$desired_dir = "upload/";
if (empty($errors)) {
if (is_dir($desired_dir) == false) {
mkdir("$desired_dir", 0700);
}
if (move_uploaded_file($file_tmp, "$desired_dir/" . $file_name . $sExt)) {
$uploadedFiles[$key] = array($file_name . $sExt, 1);
} else {
echo "Couldn't upload file " . $_FILES['files']['name'][$key];
$uploadedFiles[$key] = array($_FILES['files']['name'][$key], 0);
}
} else {
}
}
function compress($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
}
imagejpeg($image, $destination, $quality);
return $destination;
}
$source_img = $uploadedFiles;
$destination_img = 'compres/';
$d = compress($source_img, $destination_img, 60);
foreach ($uploadedFiles as $key => $row) {
if (!empty($row[1])) {
$codestr = '$file' . ($key + 1) . ' = $row[0];';
eval($codestr);
} else {
$codestr = '$file' . ($key + 1) . ' = NULL;';
eval($codestr);
}
}
}
The problem with your code is that $file_name is the same for all images. Also you did not get the correct image resource. Here is the working solution:
<?php
if (!empty($_POST)) {
$newname = md5(rand() * time());
if (isset($_FILES['files'])) {
$uploadedFiles = array();
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$errors = array();
$file_name = md5(uniqid("") . time());
sleep(1);//We give a second for breathing
$file_size = $_FILES['files']['size'][$key];
$file_tmp = $_FILES['files']['tmp_name'][$key];
$file_type = $_FILES['files']['type'][$key];
$filename = $_FILES["files"]["name"][$key];
if ($file_type == "image/gif") {
$sExt = ".gif";
} elseif ($file_type == "image/jpeg" || $file_type == "image/pjpeg") {
$sExt = ".jpg";
} elseif ($file_type == "image/png" || $file_type == "image/x-png") {
$sExt = ".png";
}
if (!in_array($sExt, array('.gif', '.jpg', '.png'))) {
$errors[] = "Image types alowed are (.gif, .jpg, .png) only!";
}
if ($file_size > 2097152000) {
$errors[] = 'File size must be less than 2 MB';
}
$desired_dir = "upload/";
if (empty($errors)) {
if (is_dir($desired_dir) == false) {
mkdir("$desired_dir", 0700);
}
if (move_uploaded_file($file_tmp, $desired_dir . $file_name . $sExt)) {
$uploadedFiles[$key] = array($file_name . $sExt, 1);
} else {
echo "Couldn't upload file " . $_FILES['files']['name'][$key];
$uploadedFiles[$key] = array($_FILES['files']['name'][$key], 0);
}
} else {
print_r($errors);
}
}
function compress($filename, $destination, $quality) {
$info = getimagesize($filename);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($filename);
} elseif ($info['mime'] == 'image/gif') {
$image = imagecreatefromgif($filename);
} elseif($info['mime'] == 'image/png') {
$image = imagecreatefrompng($filename);
}else{
$image =null;
}
return imagejpeg($image, $destination, $quality);
}
$compressed = 0;
$destination_img = 'compressed/';
foreach($uploadedFiles as $km=>$val){
$photos = $desired_dir . $val[0];
$compressed += compress($photos, $destination_img.$val[0], 60);
}
if($compressed>=1){
echo $compressed.' Images compresses';
}else{
echo 'No Image Compressed';
}
}
}
?>
<form method="POST" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="file" name="files[]">File 1<br>
<input type="file" name="files[]">File 2<br>
<input type="file" name="files[]">File 3<br>
<input type="submit" name="filesubmit" value="Submit">
</form>
Check the following links to better understand how image processing and generation:
imagejpeg()
getimagesize()
I hope my answer helps you.

not able to insert image height and image width in database using codeigniter

This is my controller code:
if ($files != '0') {
//echo "1";
if (isset($is_anonymous)) {
$is_anonymous = $is_anonymous;
} else {
$is_anonymous = "0";
}
$file_ary = $this->Jayesh($_FILES['files']);
$post_Id = $this->post_m->add_new_post($is_anonymous, $college_id, $writepost, $post, $article, $askq, $user_id, curr_date(), $v_id, $art_title, $art_image, $art_domain, $art_url, $article);
foreach ($file_ary as $file) {
$srt = explode('.', $file['name']);
$ext = $this->getExtension($file['name']);
$fiel_name = uniqid() . date("YmdHis") . "." . $ext;
$mime = $file['type'];
if (strstr($mime, "video/") || strstr($mime, "application/")) {
$filetype = "video";
$sourcePath = $file['tmp_name'];
$targetPath = "images/medical_college_images/video/" . $fiel_name;
//move_uploaded_file($sourcePath, $targetPath);
$s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
} else if (strstr($mime, "image/")) {
$filetype = "image";
$sourcePath = $file['tmp_name'];
$targetPath = "images/medical_college_images/image/" . $fiel_name;
//move_uploaded_file($sourcePath, $targetPath);
$s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
} else if (strstr($mime, "audio/")) {
$filetype = "audio";
}
if (isset($_POST['user_id'])) {
$user_id = $_POST['user_id'];
if (!empty($user_id)) {
$user = $this->post_m->check_user_exist_timeline($user_id);
if (!empty($user)) {
if ($filetype == 'video') {
$image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/video/" . $fiel_name);
$image_width = '0';
$image_height = '0';
$video_width = '300';
$video_height = '160';
}
if ($filetype == 'image') {
//echo "https://d2c8oti4is0ms3.cloudfront.net/images/healthwall_media/image/".$fiel_name;
$image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/image/" . $fiel_name);
$image_width = $image_info[0];
$image_height = $image_info[1];
$video_width = '300';
$video_height = '160';
}
//exit();
/* $last_user_id = $this->post_m->insert_image_post_into_media($fiel_name, $filetype,curr_date());
if (!empty($last_user_id))
{ */
$result = $this->post_m->insert_image_post_into_post_media($post_Id, curr_date(), $image_width, $image_height, $video_height, $video_width, $fiel_name, $filetype);
//}
}
}
}
}
Model code:
public function insert_image_post_into_post_media($post_Id, $cdate, $image_width, $image_height, $video_height, $video_width, $fiel_name, $filetype) {
$sql = "INSERT INTO college_post_media( `post_id`,`type`, `source`, `img_height`, `img_width`, `video_height`, `video_width`, `created_at`, `updated_at`, `deleted_at`)
VALUES ('$post_Id','$filetype','$fiel_name','$image_height', '$image_width','$video_height', '$video_width', '$cdate','$cdate','$cdate')";
return $result = $this->db->query($sql);
}
I'm facing an issue when inserting img_height and img_width in to the table. It is going in empty.
Try getting the image size while it is still on your domain:
Excerpt:
} else if (strstr($mime, "image/")) {
$filetype = "image";
$sourcePath = $file['tmp_name'];
list($image_width, $image_height) = getimagesize($file['tmp_name']);
$targetPath = "images/medical_college_images/image/" . $fiel_name;
//move_uploaded_file($sourcePath, $targetPath);
$s3->putObjectFile($sourcePath, $bucket, $targetPath, S3::ACL_PUBLIC_READ);
}
Assuming that $file['tmp_name'] is a fully qualified path.
Then you can remove:
$image_info = getimagesize("https://medicalwale.s3.amazonaws.com/images/medical_college_images/image/" . $fiel_name);
$image_width = $image_info[0];
$image_height = $image_info[1];

File not uploading into database. Validation ok?

I have a site where users can upload photos from mobile, but all the photos that are uploaded from mobiles, show 90 degrees to the left when upload. I fixed this problem but now, after the file is validated, its not going into the db. please any help..
Share script code is:
<?php
require('help.php');
if(isset($_POST['submit'])){
$title = $_POST['title'];
$content = $_POST['content'];
$posted = $_POST['posted'];
$date = date("Y-m-d H:i:s");
$ip = $_SERVER["REMOTE_ADDR"];
$rand = rand(1,1000000);
if(empty($title)){
echo "Titulli eshte bosh.";
}else if(empty($content)){
echo "Permbajtja eshte bosh.";
}else if(empty($_FILES['file']['name'])){
echo "Imazhi eshte bosh.";
}else if($_FILES['file']['name']){
$name = htmlspecialchars($_FILES['file']['name']);
$ext = end((explode(".", $name)));
$ext = strtolower($ext);
//if no errors...
if(!$_FILES['file']['error']){
//now is the time to modify the future file name and validate the file
$new_file_name = date('ymdHisu'). ".". $ext;
if($_FILES['file']['size'] > (6144000)){
$valid_file = false;
echo 'Oops! Your file\'s size is to large.';
}
elseif($ext !== "jpg" && $ext !== "png" && $ext !== "jpeg" && $ext != "gif" && $ext !== "bmp") {
$valid_file = false;
echo "Your file must be in jpg, jpeg, png, gif, or bmp formats.";
}else{
$valid_file = true;
}
//if the file has passed the test
if($valid_file){
//move it to where we want it to be
move_uploaded_file($_FILES['file']['tmp_name'], 'images/'.$new_file_name);
$exif_read = exif_read_data("images/".$new_file_name);
if(!empty($exif_read['Orientation'])){
$orientation_data = exif_read_data("images/".$new_file_name)['Orientation'];
}
if(isset($orientation_data) && $orientation_data !== 1){
$path = "images/". $new_file_name;
$buffer = ImageCreateFromJPEG($path);
$exif = exif_read_data($path);
if(!empty($exif['Orientation'])){
switch($exif['Orientation']){
case 8:
$buffer = imagerotate($buffer,90,0);
break;
case 3:
$buffer = imagerotate($buffer,180,0);
break;
case 6:
$buffer = imagerotate($buffer,-90,0);
break;
}
$image = imagejpeg($buffer, $path, 90);
}
}
if(empty($posted)){
$posted = 'Anonim';
}
$sql = "INSERT INTO problems(title, content, date, image, posted, ip) VALUES (:title, :content, :date, :image, :posted, :ip)";
$query = $db->prepare($sql);
$results = $query->execute(array(
':title' => htmlentities ($title),
':content' => htmlentities ($content),
':date' => $date,
':image' => $path,
':posted' => htmlentities ($posted),
':ip' => $ip
));
echo "<div id='ok'>Lajmi u raportua me sukses. Kontrollojeni <a href='index.php'>ketu</a> .</div>";
}
}else{
//set that to be the returned message
echo 'Ooops! Your upload triggered the following error: '.$_FILES['file']['error'];
}
}
}
?>
Problem:
after the file is validated, its not going into the db.
Solution
That's because your $path is undefined when you try to insert record into the database. Move the $path variable outside of the if(isset($orientation_data) && $orientation_data !== 1){ ... } block, like this:
// your code
$path = "images/". $new_file_name; // moved this outside of the if block
if(isset($orientation_data) && $orientation_data !== 1){
$buffer = ImageCreateFromJPEG($path);
$exif = exif_read_data($path);
if(!empty($exif['Orientation'])){
switch($exif['Orientation']){
case 8:
$buffer = imagerotate($buffer,90,0);
break;
case 3:
$buffer = imagerotate($buffer,180,0);
break;
case 6:
$buffer = imagerotate($buffer,-90,0);
break;
}
$image = imagejpeg($buffer, $path, 90);
}
}
// your code

Categories