我真的需要另一个大脑。我有一个脚本,可以生成三个不同版本的图像,并将它们保存在不同的文件夹(大,中,缩略图)中。它调整大小并将它们放在文件夹中,但是大文件不可读(另外两个是)。它与文件夹无关,所以我被卡住了......
这是我的(简化)代码:
<?php
$target_folder = "images/";
$uploads_dir = $target_folder;
$upload_image = $_FILES['Filedata']['tmp_name'];
$id = $_POST['post_id'];
$image_name = $id . "." . time(); //this just generates the image name
$large_name = $target_folder . "large/" . $image_name . ".jpg";
$medium_name = $target_folder . "medium/" . $image_name . ".jpg";
$small_name = $target_folder . "small/" . $image_name . ".jpg";
list($width, $height) = getimagesize($upload_image); //width/height of original image
$medium_newwidth = $width * 0.60; //scales image down to 60%
$medium_newheight = $height * 0.60;
$small_newwidth = $width * 0.20; //scales image down to 20%
$small_newheight = $height * 0.20;
$large = imagecreatefromjpeg($upload_image); //here's where I think the problem might be
$medium = imagecreatetruecolor($medium_newwidth, $medium_newheight);
$small = imagecreatetruecolor($small_newwidth, $small_newheight);
imagecopyresized($medium, $large, 0, 0, 0, 0, $medium_newwidth, $medium_newheight, $width, $height);
imagecopyresized($small, $large, 0, 0, 0, 0, $small_newwidth, $small_newheight, $width, $height);
imagejpeg($medium, $medium_name, 100);
imagejpeg($small, $small_name, 100);
rename($upload_image, $large_name);
?>
有什么想法吗?
谢谢!
答案 0 :(得分:3)
如果您想使用原始上传,则应使用move_uploaded_file
代替rename
。或者,您可以保存大图像,就像您正在使用其他图像一样:
imagejpeg($large, $large_name, 100);