如何使用 Image Resizer 使缩略图转到 /tmp/thumb/ 并将原始图像保留在 /tmp/ 上?

发布于 2024-07-24 10:10:54 字数 680 浏览 3 评论 0原文

我正在尝试使用图像调整器,我得到了以下代码

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);
    }

现在,原始图像和缩略图将放置在同一文件夹中。

让我知道..

来源

I'm trying to play with image resizer and I got the following code

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);
    }

For now, the original image and the thumbnail will place in same folder.

Let me know..

Source

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深爱不及久伴 2024-07-31 10:10:55

嘿伙计,这看起来非常困难,但可以简单地使用 Thumbnailer 库及其上传助手来制作:

function callback(& $thumb) {
   $thumb->thumbSquare(100)->save("/tmp/thumb/".$thumb->filename);
}

Thumbnailer::upload('ulimage', 'callback');

非常简单: )

Hey man, this looks very tough, but can be made simply using the Thumbnailer library and its upload helper:

function callback(& $thumb) {
   $thumb->thumbSquare(100)->save("/tmp/thumb/".$thumb->filename);
}

Thumbnailer::upload('ulimage', 'callback');

Very easy :)

梨涡少年 2024-07-31 10:10:54

好吧,答案是:

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);
}

但也许您想在使用之前先了解一下从网上复制和粘贴的代码。 使用 $_ vars 而不转义系统并使用 @ 隐藏错误并不是真正需要信任...

编辑:我正在提供建议,但也许最好也给出一些解释。

// 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);
}

Well, the answer is :

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);
}

But maybe you'd like to understand a bit the code you copy and past from the Net before using it. Using $_ vars without escaping system and with @ to hide error is not really calling for trust...

EDIT : I'm giving advices, but maybe it's better to give some explanation as well.

// 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文