如何使用PHP将图片导出到本地文件夹,我所有的数据都在服务器系统中。如何在客户端系统中导出上传的图片?请给我一个解决方案。我使用的是Php。感谢所有人。
发布于 2016-05-28 18:22:25
要么你为图像保留一个压缩文件。并直接请求url。如果图像文件夹是静态的,则不使用php。如果图像文件夹不是静态的,并且图像被添加/删除,您可以使用php zip库创建一个zip。这将是最好的选择,以便在客户端机器上下载多个图像。
您可以使用下面的代码。下面的代码来自How to zip a whole folder using PHP的另一个堆栈溢出帖子
// 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();发布于 2016-05-28 18:23:23
试试看。参考:https://stackoverflow.com/a/724564/4669350
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');https://stackoverflow.com/questions/37497767
复制相似问题