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.
Asked
Active
Viewed 976 times
1
-
2use `move_uploaded_file` – keziah May 28 '16 at 10:17
-
from server to client? where does your php code run? server or client? – WeiYuan May 28 '16 at 10:18
-
try this http://stackoverflow.com/questions/12094080/download-files-from-server-php – JYoThI May 28 '16 at 10:21
-
my php code run in server. I will try other answers given by you. Thanks once again – sulakshana May 28 '16 at 10:24
-
like this: http://stackoverflow.com/a/12689043/4669350 – WeiYuan May 28 '16 at 10:26
-
'PHP doesn't download to clients. The client (i.e. a browser) can download from a server, and the server may use PHP to send the data.' ? So, do u want which one? download form client or send to client from server? – WeiYuan May 28 '16 at 10:28
-
sir, i want to send images to client from server – sulakshana May 28 '16 at 10:33
-
You can't do this, the only way is to provide download link of the image to user, then user can save it in the local folders. – Akam May 28 '16 at 11:13
-
I did not get the result. Pls. If I use downlink and image is not downloading. – sulakshana May 30 '16 at 07:49
2 Answers
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();
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');