$fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // make the random file name $randName = md5(rand() * time()); // and now we have the unique file name for the upload file $filePath = $imagesDir . $randName . '.' . $ext; $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo "Error uploading file"; exit; } /////////////////////// $result = move_uploaded_file($tmpName, $filePath); $orig_image = imagecreatefromjpeg($filePath); // how about other image types $image_info = getimagesize($filePath); $width_orig = $image_info[0]; // current width as found in image file $height_orig = $image_info[1]; // current height as found in image file $width = 1024; // new image width $height = 768; // new image height $destination_image = imagecreatetruecolor($width, $height); imagecopyresampled($destination_image, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // This will just copy the new image over the original at the same filePath. imagejpeg($destination_image, $filePath, 100) ///////////////////////// if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); }