1

how to export images to the local folder using PHP, my all the data is in server system. How i export uploaded images in client system ? Please give me solution. I am using Php. Thanks to all.

sulakshana
  • 19
  • 2

2 Answers2

0

Either you keep a zipped file for images. And request the url directly. No role of php, if the images folder is static. In case the image folder is not static, and the images are added/deleted, you can create a zip using php zip library. That would be the best option in order to download multiple images at clients machine.

You can use the code as below. The code below is from another stack overflow post at 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();
Community
  • 1
  • 1
Aditya
  • 861
  • 5
  • 8
0

Try it. Reference: 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');
Community
  • 1
  • 1
WeiYuan
  • 5,922
  • 2
  • 16
  • 22