I'm using this script below to display the users image after uploading, it also will resize the image too. Everything works fine, but can't figure out how to save the resized image to the /temp/ folder. the steps are 1. upload 2. resize image if needed 3. display image to the user 4. save displayed/resized image to /temp/ folder.
PHP Code:
<?php
// Get the session Id passed from Upload. We have to do this to work-around the Flash Player Cookie Bug
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
} else if (isset($_GET["PHPSESSID"])) {
session_id($_GET["PHPSESSID"]);
}
session_start();
// Check the upload
if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
header("HTTP/1.1 500 Internal Server Error");
echo "invalid upload";
exit(0);
}
// Get the image and create a thumbnail
$img = @imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
if (!$img) {
header("HTTP/1.1 500 Internal Server Error");
echo "could not create image handle";
exit(0);
}
$width = imageSX($img);
$height = imageSY($img);
// Check if image is too small
if ($width < 160 || $height < 120 ) {
header("HTTP/1.1 200 Internal Server Error");
echo "Invalid width or height. Your image is way to small.";
exit(0);
}
// Resize if image is bigger than 640x480
if ($width > 640 || $height >= 480 ) {