PHP-код
Что-то не так в этом php-коде?
<?php require '../db_connect.php'; if (isset($_POST['message']) && !empty($_POST['message']) or isset($_POST['img_file']) && !empty($_POST['img_file']) or isset($_POST['video_file']) && !empty($_POST['video_file'])) { $message=$_POST['message']; $user_id=$_POST['user_id']; //$user_id=1; date_default_timezone_set('Asia/Kolkata'); $date = date('Ymd H:i:s'); $query=mysqli_query($con,"INSERT INTO posts(user_id,post_description,is_active,created_at) values('".$user_id."','".$message."',1,'".$date."')"); if($query){ $i_post_id = mysqli_insert_id($con); if(isset($_POST['img_file'])){ $sourcePath = $_POST['img_file']; // create dir if not exists if(!is_dir('../img/Post')){ mkdir('../img/Post',0777,true); } $s_file_name = time()."_".$_POST['img_file']; $targetPath = "../img/Post/".$s_file_name; if(move_uploaded_file($sourcePath,$targetPath)) { 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 = $targetPath; if(!is_dir('../img/Post/compress')){ mkdir('../img/Post/compress'); } $destination_img = '../img/Post/compress/'.$s_file_name; $d = compress($source_img, $destination_img, 50); $i_file_type = 1; // 1 for image. $query=mysqli_query($con,"INSERT INTO post_files(post_id,file_name,file_type,is_active) values('".$i_post_id."','".$s_file_name."',$i_file_type,1)"); } } if(isset($_POST['video_file'])){ //echo "in"; $sourcePath = $_POST['video_file']; // create dir if not exists if(!is_dir('../img/Post')){ mkdir('../img/Post',0777,true); } $s_file_name = time()."_".pathinfo($_POST['video_file'], PATHINFO_FILENAME).".mp4"; $s_file_name = str_replace(' ', '_', $s_file_name); $targetPath = "../img/Post/convert/".$s_file_name; if(!is_dir('../img/Post/convert')){ mkdir('../img/Post/convert',0777,true); } $s_post_path = dirname(__FILE__).'/'; $handbrake = "HandBrake/HandBrakeCLI"; $cmd = $s_post_path.$handbrake." -i ".$sourcePath." -o ".$s_post_path.$targetPath." -e x264 -q 25 -r 15 -B 64 -X 480 -O"; passthru($cmd,$err); $i_file_type = 2; // 2 for video. $query=mysqli_query($con,"INSERT INTO post_files(post_id,file_name,file_type,is_active) values('".$i_post_id."','".$s_file_name."',$i_file_type,1)"); } $response["success"] = 1; $response["message"] = "Post successfully added."; // echoing JSON response echo json_encode($response); } else{ $response["success"] = 0; $response["message"] = "Oops! An error occurred."; // echoing JSON response echo json_encode($response); } } ?>
Когда я загружаю изображение в базу данных Mysql, он не загружает и не показывает мне изображение в виде строки в LOG например =
img_file = /9j/ 4 AAQSkZJRgABAQAAAQABAAD / 2 wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkz ODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P / 2 wBDARESEhgVGC8aGi9jQjhCY2NjY2Nj Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P / wAARCBBACSQDASIA AhEBAxEB / 8 QAGwABAQEBAQEBAQAAAAAAAAAAAQACBwYFBAP / xABKEAACAgIBAwMDAQUEBgkDAAsA AREhMUECA1FhBAVxBhKBkQc1cqGxEyIyNBQVFjNCUiM2U1RVYnOSwRclgiTR4fBDRPFjRSaD / 8 QA FgEBAQEAAAAAAAAAAAAAAAAAAAEC / 8 QAFxEBAQEBAAAAAAAAAAAAAAAAAAERQf / aAAwDAQACEQMR AD8A8KSAQ2SJQwl4kKkIDoBRP + YJzsANESJ6AGwFuydBEoUypJFoAGPIOhTJhGS4uHOSFAUkxaoy FQpUSyKj5AGoImKrIQNUCN8nWDAUr5KARqHEgDKARtpAZRpA4yimwEzAvlsJAYrJkQgK0UmbEI0n CJw1INMgozZaGQCFDNGfgtWBCncfzDRQ9AacSD8otWEgX4FKVbKu5UBlijX2zaKKkDM + BmhwZeAA skiQCObQRQzoCkHdiAEi2SkvufgCFcmgIBaWUBFYQ9yXYCASqSTL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JCkiqRkAcaMyPJVJkDUjAJFV2ESYtrSAkBZLXYSfaaAOLgXEVkyyQEJQWAq0PFNgaxnI BNk8lbJ58hQxRbNPsAPwGUWCTAiyUtsUED41MhRppO0ZdASJsk4B2BGktmUaAp8BEGl9u0DbdaAo KCHAUEXmS0EGxUgh0BNvZlmn2MtMCGQFAOQFOgbkCWShgL7APFwxbnCgEqEAXFsDUqDLyEScMZM5 YhTOgKgAVbF + BTLDoAgkTZSFLMti / ARYQCsAKbAmA7sgJoVGTMjLAW5eARXHyCA1uiRTRbkAIQYF YvApSgi4ACGpoICIoCxlgQC5my / qBETICFAmMhRyJKxommAYZpGUIE / ATGhyxgAmAQsFkCYGqDAD xgnBVHkFPYBhAQqGAbBjNgBKNjSDRBDJAhCoZonEUACsTstAqodAGinwLoAJoBaKAKCIAEmRZoAA WqKAK0RMghSlgScCgJEhcFWAoZMnkywjUyUWCY5ArJOGOjLAW13AUTYAMSgNVoKIsvA5ABThRCAH kUgFPuZZoG0wgQoNClsCdkQ0AQQuOwbAlkX3ApAnZPwTZIKGKkhSoDLkjW7KFKuQBAhcLY8YAo2B pwWQrOEBpwidOAjIoDVBFLagJgUEBUQpKLBgVCu5mRQQtrtYPA0tFlBWTWggVkBSA1xmycRIGSLZ ADjsSFkkFDsoYuOxaCBEOES8gBEX5AtizJqaAHgeOCDACy0TckgLwSYMFmgNyk7CtAxXkBRcv5Ah 8 ADUAabSV2zACUkQERIpANihSB5AkKhqEZIBmGUgXwAwyFRcgwKWnKFOVEmRAiUkQFgpJpxNA + wC P3OIMo1AAUrsTKJAiRGkpU0BnZMSfeALKMiieQJMiXcWADAQKAGigWH3SrAiNKIsgAmoFAADGxcR RKgoafYPBqYB0ESSdFyqiAKkJImAMkPGHknE0EBQQptAUEyVuxdVMgZIWQFBFMA2A0UgQFIyCICG aAkFTEvgpqAJWLhpGZKwEieClATgCIIkKsIEAotWQgUptE92Tj4BOwNKkDKYVBIE
Как загрузить изображение из этого php-файла? Что не так в этом файле php?