Copy a zip file from an external website to my server - php

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)

Related

Zip file download system laravel

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.

how can i restrict a file being viewed or downloaded using url? i want same file to be downloaded using php script

I want to restrict a pdf file on my server from being viewed or downloaded. for example, when somebody types below url in browser and press enter.
http://example.com/pdf/sample-pdf1.pdf
the file should not be viewed or downloaded. instead, it should get redirected somewhere else or should display some error message
But, when i download the same file using php or html code, it should get downloaded
for example when i use below code in a php file, it should get downloaded.
[a href="http://example.com/pdf/sample-pdf1.pdf" download]Download[/a]
Insert .htaccess file inside pdf directory with content:
"Deny from all" -
That will not allow access that directory and files inside it via URL.

displaying pdf files located in temp folder using IFrame

Well, I got an API which read binary file from database and store it as "PDF" in windows temp folder, then it sends the path to that file to "PHP" page. What I want is to display that file over the browser.
The API returns the PDF file path: C:\Users\username\APPDATA\Local\Temp\some file.pdf. What I have done is setting that path to an iframe in my page,
but it shows nothing.
What am I missing here?
You should convert that local path to an url one.
Http://www.yourpage.com/folder_where_you_keep_those_files/file.pdf
And give the proper folder and file permissions.
The PDF is on YOUR computer, the user cannot access YOUR C:\ drive.
You cannot exchange your client-side files with someone server-side.
Store your PDF file on the server somewhere and set that path in the iframe.
You need to move that file from you local path (it can be your tmp folder or another folder that is not in your web accessible path) to your web directory so that you can put that in your iframe source.
Eg:
<iframe src="http://yourwebsite.com/somepdf.pdf" width="1000px" height="800px" >

Save file to server instead of my computer on PHP

I have a url that downloads a .csv file to my computer like this
http://oi62.tinypic.com/2nh0zzt.jpg
The url is
api.infortisa.com/api/Tarifa/GetFile?user=xxxxxxxxxxxxxxxx
But what I want is to download that file in a folder of the server, or at least open it's content so I can save it where i want.
(upload that file via FTP every time is a pain)
I can't access the direct url of the file, just what the api gives me, and that is just a direct download.
I tried curl and file_get_contents, but nothing seems to work.
How can I download that file in the server instead of my computer?
Any help would be appreciated.

PHP Download file from non-hosted directory

I've been able to upload a file through PHP to a non-hosted directory (directory is not on the website) with read/write permissions for the PHP file (www). How would I download the file from this directory? I've been able to list the contents of the directory, but clicking on the files (made the filenames links) does not work as the computer attempts to download the file from the path on the server. I'm new to PHP, so all help is appreciated. Thanks!
Edit: Before I get down votes for this being a broad question, I just want to know how to access the files in the non-hosted directory and pass them to the user. I already know how to download normal files hosted on the website. Thanks!
You can use a delegating PHP file for file access. I don't know anything about your structure, but if you can write it, you can (presumably) read it back with file_get_contents:
<?php
echo file_get_contents('/the/path/to/the/unhosted/directory/file.ext');
?>

Categories