so I need your solution.
my site, example.com/test.php when user click on it, it will download file from external site externalsite.com/file.mkv
I just want to mask the external site url, so that when user click on example.com/test.php it will get file from external site url and never show original site url.
I have try below code but not working
<?php
$id = $_GET['id'];
$filename = "https://externalsite.com/20230113100300if_/https%3A%2F%2Fs38.123apps.com%2Fvconv%2Fd%2F63c12a662da0e_mkv_ymfVHPvq.mkv";
header("Content-disposition: attachment; filename=".$filename."");
header('Content-type: application/octet-stream');
readfile($filename);
?>
Change the name in the Content-disposition: header to just the basename, not the full URL.
So replace
header("Content-disposition: attachment; filename=".$filename."");
with
header("Content-disposition: attachment; filename=".basename($filename));
Related
$file_name = $_GET['name'];
$file_url = $_GET['file-url'] . $file_name;
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$file_name."\"");
readfile($file_url);
exit;
I'm using this code to download files in my site fetching from another web servers.
It works if my url looks like this:-
https://www.example.com/file_download.php?name=video_song.mp4&file-url=http://www.googlevideo.com/video/play/221589
So, it starts downloading by fetching the file from http://www.googlevideo.com/video/play/221589 in my site. Now, though it downloads the file correctly, it does allow the downloader to see the actual size of the file. So, downloaders having problems with it (e.g. Time Remaining, Download Percentage etc.).
So what header should I use to solve this thing? Please explain it by coding.
You may try this:
header("Content-Length: " . $filesize);
I use header() to download an xlsx file from given url. The file is downloaded but I can't not open it. It shows error
Below is my code
$url = "http://example.com/attachment/file.xlsx"
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Disposition: attachment; filename=Test.xlsx');
readfile($url);
exit();
Randy, your question looks weird. The URL in the serve response is way different than the one in your code.
Before commencing the download - sending the headers, do a is_file() or other check on the URL and only start the download if the file exists.
I suspect you are trying fopen on URL, not local file and the URL may be either incorrect or on server not allowing fopen on URLs.
Sample:
$url = "http://example.com/attachment/file.xlsx";
if (!fopen($url,'r')) exit('File/URL not accessible');
else fclose($url);
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename=Test.xlsx');
readfile($url);
exit();
I have mp3 file url and I want to make it downloadable for user.
I'm using below code but this is not working.
<?php
$file = 'http://r1---sn-2uja-pncz.googlevideo.com/videoplayback?pl=17&ip=39.33.149.149&ms=au&mt=1460124725&mv=m&id=o-ALL1b-5qDY-vJciSMtIjNoeHW6NSl0a67lvMj_IDTJ_V&mm=31&mn=sn-2uja-pncz&keepalive=yes&clen=3694396&pcm2cms=yes&sparams=clen,dur,gir,id,initcwndbps,ip,ipbits,itag,keepalive,lmt,mime,mm,mn,ms,mv,pcm2cms,pl,source,upn,expire&ipbits=0&initcwndbps=163750&mime=audio/webm&lmt=1404826626593256&source=youtube&dur=290.350&gir=yes&key=yt6&signature=07AF8F194980DA82DA85AC08FFCC99CA8E459336.38D33A3B46AD95087B779B646C8139A85EE55555&fexp=9405969,9416126,9416891,9420452,9422596,9423662,9426926,9427902,9428398,9429294,9429854,9431270,9432651,9433088,9433186,9433425,9433703&sver=3&upn=j6a9XvntKKY&expire=1460146538&itag=171';
// URL is not path of mp3 file but exact mp3 file
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
Any suggestion why this is not working.
UPDATE
I try below code and it give forbidden 403 access.
header('Content-type: application/mp3');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
These codes are working for .mp3 files not not direct url like this $file because there is not .mp3 but url which return mp3 file formate.
mp3 is playing well in this url, Now how can I download it.
I have a .TXT file on my xampp server, if a user clicks on a link it should download, but instead it opens up in my browser window.
My code looks as follows:
<?php echo $files->task_verify_file;?>
any one solve the problem thanks
I did it like this:
if (file_exists ($file)) {
header("Content-Type: text/plain; charset=utf-8");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$filename);
readfile($file);
}
How can I allow users to download pictures saved on the server? The goal is to have the user click on a link and have a specified image to start to download.
Facebook example:
Make the link to another .php page, not the image. Then on that page use the content-disposition header like this:
<?php
// Define the name of image after downloaded
header('Content-Disposition: attachment; filename="file.jpg"');
// Read the original image file
readfile('file.jpg');
?>
From there, you can just add the filename of the image in a get command like
`download.php?filename=file`
then reference that in the file as:
readfile($_GET['filename'].'.jpg')
You need to set a specific header on the response that delivers the image in order to force a download.
Content-Disposition: attachment; filename=myawesomefilename.png
Otherwise it will just load up in browser.
So send that header and then just link to the path that delivers that image with that header.
Send a header to tell the browser to download it like this:
header("Content-type: application/force-download")
Then send them the data for the file itself without any HTML or anything.
This example is snipped from the PHP docs
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
If by "download pictures saved on the server" you mean "try to make the browser offer a 'save as' dialog box instead of just displaying the image" then you might want to look into using the Content-Disposition: attachment header in the response that serves the image:
Content-Disposition: attachment; filename="thefilename.jpg"
You can set headers in php using the header function.