} else { if ($picture_mode == "delete_media_image") { $media_name = $_POST['image_name']; unlink("images/" . $media_name); $response = array("result" => "done"); echo json_encode($response); } else { if ($picture_mode == "media_image") { $source = $_FILES['media_image']['tmp_name']; $image_name = $userid . "_" . round(microtime(true) * 1000); $destination = "images/{$image_name}.jpg"; move_uploaded_file($source, $destination); $imageSize = 20; $size = filesize($destination); if (filesize($destination) > 15000) { $size = compressImage($destination, $destination, $imageSize); } $size = $size / 1024; $response_image_path = $_SERVER['HTTP_HOST'] . "/" . $destination; $response = array("result" => "done", "path" => $response_image_path, "size" => $size, "source" => $source); echo json_encode($response); } else { if ($picture_mode == "media_video") { $sourceFile = $_FILES['media_video']['tmp_name']; $name = $_FILES['media_video']['name']; $video_name = $userid . "_" . $name; $destination = "videos/{$video_name}"; move_uploaded_file($sourceFile, $destination); $video_path = $_SERVER['HTTP_HOST'] . "/" . $destination; $response = array("result" => "done", "path" => $video_path); echo json_encode($response);
if (strlen($imagename)) { $image_path = $_FILES['photoimg']['name']; $ext = pathinfo($image_path, PATHINFO_EXTENSION); $filename = pathinfo($image_path, PATHINFO_FILENAME); if (in_array($ext, $valid_formats)) { if ($size < 1024 * 1024) { $random_file_name = md5($filename . time()) . "." . $ext; $actual_image_name = $path . $random_file_name; $database_save_image_name = $database_save_path . $random_file_name; $uploadedfile = $_FILES['photoimg']['tmp_name']; //Re-sizing image. include 'compressImage.php'; $widthArray = array(200, 100, 50); //required custom dimension here. foreach ($widthArray as $newwidth) { $filename = compressImage($ext, $uploadedfile, $path, $actual_image_name, $newwidth); //echo "<img src='".$filename."' class='img'/>"; } //Original Image if (move_uploaded_file($uploadedfile, $actual_image_name)) { //Insert upload image files names into user_uploads table $student_id = trim($_POST['student_id']); if ($my_id == $student_id) { $qry = "UPDATE student_details SET profile_pic_name = '{$database_save_image_name}' where student_id='{$student_id}'"; mysql_query($qry) or die(mysql_error()); $msg .= ""; } else { $msg .= "Unfair attemp :( "; } $_SESSION['upload_image_msg'] = $msg; header("Location:profile.php");
$output_dir = $image_path; } if (isset($_FILES["images"])) { $ret = array(); global $compression_level; $error = $_FILES["images"]["error"]; //You need to handle both cases //If Any browser does not support serializing of multiple files using FormData() if (!is_array($_FILES["images"]["name"])) { $fileName = $_FILES["images"]["name"]; move_uploaded_file($_FILES["images"]["tmp_name"], $output_dir . $fileName); $ret[] = $fileName; $partes = explode('.', $_FILES["images"]["name"]); $ext = $partes[count($partes) - 1]; $comp_name = str_replace("." . $ext, "_thumb." . $ext, $_FILES["images"]["name"]); compressImage($image_path . $_FILES["images"]["name"], $image_path . $comp_name, $compression_level); } else { $fileCount = count($_FILES["images"]["name"]); for ($i = 0; $i < $fileCount; $i++) { $fileName = $_FILES["images"]["name"][$i]; move_uploaded_file($_FILES["images"]["tmp_name"][$i], $output_dir . $fileName); $ret[] = $fileName; } } echo json_encode($ret); } function compressImage($source_url, $destination_url, $quality) { $info = getimagesize($source_url); if ($info['mime'] == 'image/jpeg') { $image = imagecreatefromjpeg($source_url);