Php 如何使用图像大小调整器使缩略图转到/tmp/thumb/并保持原始图像在/tmp/上?
我正在尝试使用图像大小调整器,我得到了以下代码Php 如何使用图像大小调整器使缩略图转到/tmp/thumb/并保持原始图像在/tmp/上?,php,image,thumbnails,Php,Image,Thumbnails,我正在尝试使用图像大小调整器,我得到了以下代码 if (is_uploaded_file(@$_FILES['ulimage']['tmp_name'])){ $targetfilename = ImageHelper::treatFilename(uniqid() . "_" . $_FILES['ulimage']['name']); move_uploaded_file($_FILES['ulimage']['tmp_name'], dirname(__FI
if (is_uploaded_file(@$_FILES['ulimage']['tmp_name'])){
$targetfilename = ImageHelper::treatFilename(uniqid() . "_" . $_FILES['ulimage']['name']);
move_uploaded_file($_FILES['ulimage']['tmp_name'], dirname(__FILE__) . "/tmp/" . $_FILES['ulimage']['name']);
ImageHelper::resizeImage(dirname(__FILE__) . "/tmp/" . @$_FILES['ulimage']['name'], dirname(__FILE__) . "/tmp/" . $targetfilename, $width, $height);
}
现在,原始图像和缩略图将放在同一个文件夹中
让我知道
答案是:
if (is_uploaded_file(@$_FILES['ulimage']['tmp_name']))
{
$targetfilename = ImageHelper::treatFilename(uniqid() . "_" . $_FILES['ulimage']['name']);
move_uploaded_file($_FILES['ulimage']['tmp_name'], dirname(__FILE__) . "/tmp/" . $_FILES['ulimage']['name']);
ImageHelper::resizeImage(dirname(__FILE__) . "/tmp/" . @$_FILES['ulimage']['name'], dirname(__FILE__) . "/tmp/thumb/" . $targetfilename, $width, $height);
}
但是在使用之前,你可能想了解一下你从网上复制并通过的代码。在不转义系统的情况下使用$变量并使用@隐藏错误并不是真正需要信任
编辑:我在给你提建议,但也许最好也解释一下
// first you check if the is done uploading in the tmp directory with is tmp name
if (is_uploaded_file(@$_FILES['ulimage']['tmp_name']))
{
// here, you rebuild a explicit name using the original filename and a
// unique ID to avoid erasing another one
$targetfilename = ImageHelper::treatFilename(uniqid() . "_" . $_FILES['ulimage']['name']);
// you rename the file an put it in ./tmp, a subdir of the
// script file (because of dirname(__FILE__))
move_uploaded_file($_FILES['ulimage']['tmp_name'], dirname(__FILE__) . "/tmp/" . $_FILES['ulimage']['name']);
// Here create a rezided copy
// so it's here you can decide to make it go to ./tmp/thumb
// make sure the dir exists before because you have no clue here
// if ImageHelper will create it for you if not
ImageHelper::resizeImage(dirname(__FILE__) . "/tmp/thumb/" . @$_FILES['ulimage']['name'], dirname(__FILE__) . "/tmp/thumb/" . $targetfilename, $width, $height);
}
嘿,伙计,这看起来很难,但只需使用库及其上载助手即可:
function callback(& $thumb) {
$thumb->thumbSquare(100)->save("/tmp/thumb/".$thumb->filename);
}
Thumbnailer::upload('ulimage', 'callback');
很简单:)男人们,像这样的头衔并不是真正的开脱。你能想出与你的问题更相关的东西吗?好的。。让我知道标题最好的是什么你的身体里有这个问题,我把它移到了标题上。我试着。。thumb未创建为“/tmp/thumb/”仅生成原始大小。如我所述,“确保目录之前存在,因为您不知道ImageHelper是否会为您创建该目录。您可以使用mkdir:感谢您对代码的解释..谢谢..是我创建的文件夹(777)但是缩略图不会出现。您是否手动创建了的文件夹?您是否以编程方式创建了它。根据代码,该文件不是在/tmp/thumb中创建的,而是在/path/to/script/tmp/thumb/中创建的。手动..如果我将所有路径更改为/tmp/thumb/image,则原始和thumb都将工作。