I have gotten as far as downloading a file from an external folder into a directory in my website.
The code;
<?php
$txt = file_get_contents('https://docs.google.com/document/d/1IPNaCKwzdWRVOq30saI_pIBLcL62g4_2zMmjK54yD3E/edit?usp=sharing');
file_put_contents('import.txt', $txt);
?>
I have the cron file in a folder in the same directory
https://example.com/wp-content/themes/theme-child/test.php
The code runs and a file is downloaded into the same directory with name import.txt
But the challenge is that it appears the page is downloaded as an HTML document and contains lots of CSS codes which don't exist in the file that is being downloaded.
You can check how the file I'm downloading looks like here:
https://docs.google.com/document/d/1IPNaCKwzdWRVOq30saI_pIBLcL62g4_2zMmjK54yD3E/edit?usp=sharing
So basically the downloaded file doesn't contain the target file contents. All I'm looking for is to download the file as it is without any additions.
Thanks
Related
I'm using Laravel 8
I've uploaded a zip file then want to download it. But here is a problem. After file download, it's not extracting.
Here is my code for download zip file:
$product = Product::where('id',1)->first();
$file = $product->main_file;
return response()->download($file,'filename.zip');
But, if I manually copy this zip file from my project then extract it, it's extracting fine.
Or, if I doing this: return Redirect()->to($file); It also downloads the file and extracts well without any problem. But, it's not a proper way to download. Isn't it?
So, What can I do now?
if you're trying to download via a link try this:
Download
but file name should be saved somewhere.
a simple question that's freaking me out. I created an upload zone in which files are uploaded to a folder that was dynamically created by an mkdir. But if I wanted to download that folder how do I proceed? I don't necessarily need it to be made .zip just for me to be readable and that the files inside it are intact.
I tried pointing directly at the folder with the following href but it does not work.
<td align="center"><b>Scarica Bolle</b></b></td>
php ZipArchive can't open zip file that gets downloaded from a server.
I have a zip file that I created with winrar and uploaded to my server, file location is here: http://myserver.com/uploads/test.zip It's a valid zip file
Here is my code
When I run this code all I get is
error: Not a zip archive.
It opens the file and extracts it but complains that file already exists even if I delete file.
the file that I get when I access http://myserver.com/update/test.zip get corrupted and I have no idea why, this same code that I pasted above worked just a week ago.
The problem is actually the .zip file. I downloaded it and I cannot open the file with WinZip. Please try to make a new archive and upload it again on your server.
The code looks okay so I think it just the file that is the problem.
UPDATE #1:
The .zip file is now correct. Try to delete the files before you download and extract the new files. You can use unlink("uploads/update.zip") maybe you also need to clear the uploads/temp directory first.
UPDATE #2:
The download worked now for me. Try to add this header:
header("Content-Transfer-Encoding: Binary");
Also don't forget to close the ZipArchive after extracting:
$zip->close();
I just want to copy this zip file to my server which is in an external website.
A newfile.zip is created each time but this file is empty.
I guess it's because of the format of the url, can i do something ?
<?php
$thezipfile = "http://www.tyre24.fr/user/login/userid/test/password/test/page/L2V4cG9ydC9kb3dubG9hZC90L01RPT0vYy9NVEU9Lw==";
file_put_contents('newfile.zip',file_get_contents($thezipfile));
?>
The link works.
You could always just upload the file and then put the link to the direct download in your site:
Download Project 1 (zip-file, ...kB)
Download Project 2 (zip-file, ...kB)
I have 16631 files hosted in a webserver, 2719 of them are text files that contains a list of specific files located on the server.
Using PHP, is possible to create a ZIP for each text file?
could be the text file name as ZIP file name?
I want to keep the same directory structure in the ZIP file.
Thanks in advance.
Taking the suggestion from Jeff Hines, you could use the ZipArchive class to create the zip.
In Pseudo code
Get List of Text Files in your folder
Read Text file and get list of files to add to zip
Using ZipArchive add each listed file to your new zip file.
Write flag to specify you've done this file.
You might need to run it on 10 files at a time since it may time out.