首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用php将图片导出到本地文件夹

问如何使用php将图片导出到本地文件夹
EN

Stack Overflow用户
提问于 2016-05-28 18:15:50
回答 2查看 727关注 0票数 1

如何使用PHP将图片导出到本地文件夹,我所有的数据都在服务器系统中。如何在客户端系统中导出上传的图片?请给我一个解决方案。我使用的是Php。感谢所有人。

EN

回答 2

Stack Overflow用户

发布于 2016-05-28 18:22:25

要么你为图像保留一个压缩文件。并直接请求url。如果图像文件夹是静态的,则不使用php。如果图像文件夹不是静态的,并且图像被添加/删除,您可以使用php zip库创建一个zip。这将是最好的选择,以便在客户端机器上下载多个图像。

您可以使用下面的代码。下面的代码来自How to zip a whole folder using PHP的另一个堆栈溢出帖子

代码语言:javascript
复制
// Get real path for our folder
$rootPath = realpath('folder-to-zip');

// Initialize archive object
$zip = new ZipArchive();
$zip->open('file.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);

// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);

foreach ($files as $name => $file)
{
    // Skip directories (they would be added automatically)
    if (!$file->isDir())
    {
        // Get real and relative path for current file
        $filePath = $file->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);

        // Add current file to archive
        $zip->addFile($filePath, $relativePath);
    }
}

// Zip archive will be created only after closing object
$zip->close();
票数 0
EN

Stack Overflow用户

发布于 2016-05-28 18:23:23

试试看。参考:https://stackoverflow.com/a/724564/4669350

代码语言:javascript
复制
function save_image($inPath,$outPath)
{ //Download images from remote server
    $in=    fopen($inPath, "rb");
    $out=   fopen($outPath, "wb");
    while ($chunk = fread($in,8192))
    {
        fwrite($out, $chunk, 8192);
    }
    fclose($in);
    fclose($out);
}

save_image('http://www.someimagesite.com/img.jpg','image.jpg');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37497767

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档