Forum Moderators: coopster
--------------------------
^^^ Script that gets image from previous page ^^^
--------------------------
if (!move_uploaded_file($_FILES[$upload_name]["tmp_name"], $save_path.$file_name)) {
HandleError("File could not be saved.");
exit(0);
}
if (!copy($save_path.$file_name,"uploads/thumb/".$file_name)){
HandleError("File could not be copied.");
exit(0);
}
// AT THIS POINT SCRIPT WORKS - SAME IMAGE IN TWO DIFFERENT DIRECTORIES
class ImgResizer {
private $originalFile = 'uploads/thumb/{$file_name}';
public function __construct($originalFile = 'uploads/thumb/{$file_name}') {
$this -> originalFile = $originalFile;
}
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
}
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
imagejpeg($tmp, $targetFile, 85);
}
}
$work = new ImgResizer('uploads/thumb/{$file_name}');
$work -> resize(150, 'uploads/thumb/{$file_name}');
if (!isset($_SESSION["file_info"])) {
$_SESSION["file_info"] = array();
}
$file_id = md5(rand()*10000000);
$_SESSION["file_info"][$file_id] = $file_name;
echo "FILEID:" . $file_id;// Return the file id to the script