Skip to content

Instantly share code, notes, and snippets.

@musamamasood
Last active June 30, 2021 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save musamamasood/9adc8692b0f5923977e61e67516b6ebf to your computer and use it in GitHub Desktop.
Save musamamasood/9adc8692b0f5923977e61e67516b6ebf to your computer and use it in GitHub Desktop.
Transfer files to server with publicly accessible zip file.
<?PHP
/**
* Transfer Files Server to Server using PHP Copy and PHP ZipArchive
* @link https://glowLogix.com
*/
/* Source File URL */
$remote_file_url = 'http://example.com/filename.zip';
/* New file name and path for this file */
$local_file = 'file.zip';
/* Copy the file from source url to server */
$copy = copy( $remote_file_url, $local_file );
/* Add notice for success/failure */
if( !$copy ) {
echo "Doh! Failed to copy $local_file\n";
}
else{
echo "WOOT! Success to copy $local_file...\n";
}
$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
$path = getcwd() . "/backup/"; //getcwd will get the path of file
$zip->extractTo($path);
$zip->close();
echo "<br>Woot! File has been Extracted at: $path";
} else {
echo '<br>doh!';
}
@hussnainsheikh
Copy link

Hi,

Please update the gist with my fork. Thank you! 🙂

@musamamasood
Copy link
Author

Hi,

Please update the gist with my fork. Thank you! 🙂

Okay

@hussnainsheikh
Copy link

Thank you so much! It means a lot. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment