php - php如何获取上传文件的src

标签 php mysql

我正在尝试使用一个函数来创建缩略图,我需要上传图像的src。我怎样才能得到它?

以下是我感兴趣的功能:

function make_thumb($src, $dest, $desired_width) {
    /* read the source image */
    $source_image = imagecreatefromjpeg($src);
    $width = imagesx($source_image);
    $height = imagesy($source_image);

    /* find the "desired height" of this thumbnail, relative to the desired width  */
    $desired_height = floor($height * ($desired_width / $width));

    /* create a new, "virtual" image */
    $virtual_image = imagecreatetruecolor($desired_width, $desired_height);

    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

    /* create the physical thumbnail image to its destination */
    imagejpeg($virtual_image, $dest);
}

我们将非常感谢您在这方面的帮助。

最佳答案

$src 将是您上传的原始图像

$dest 将是调整大小的图像

这些都是文件系统路径。假设这两个路径都存在于文档根目录下,您可以通过删除 $_SERVER["DOCUMENT_ROOT"]

将它们转换为 url
  $url = str_replace($_SERVER["DOCUMENT_ROOT"], realpath($dest)); 

关于php - php如何获取上传文件的src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16952951/

相关文章:

mysql插入id比较两个表

php - mySQL 查询连接关联表匹配 this AND this OR this

PHP:将 $_POST 数据发送到我的类(class)?

php - 如何在 Magento 中获取类别名称?

php - WordPress 在 Linux 服务器中建立数据库连接时出错

mysql - 如何确定表字段是否包含在插入触发器中

php - ios 比较 memcache 和 core data

javascript - 我应该使用 PHP 进行数学运算,还是转换为 JavaScript?

mysql - MariaDB/MySQL RANK() 实现

mysql - 一个查询从 A 获取,将 B 的字段值连接为 A 中的行字段,然后过滤和排序?