connect ftp account with file_get_content function - php

I have an FTP account. I want to connect to FTP with file_get_contents. Is this possible? If not, how can I do it?
I want to do this for an upload script similar to hotfile or rapidshare.

file_get_contents('ftp://username:password#host.com/');

If I understand what you want to do from your comments on #genesis' answer, what you need to do is this:
$file = file_get_contents("derpost:pass**#ftp1.freakshare.com/Freez%20Screen%20Vide‌​o%20Capture.lnk");
header('Content-Disposition: attachment; filename="image.jpg"'); // Change file name as appropriate
header('Content-Length: '.strlen($file));
header('Content-Type: image/jpeg'); // Change this MIME type as appropriate
echo $file;

Related

Change file header name in php [duplicate]

Is it possible to let your user download a file with a different name?
For example, there is a file called "4324ffsd34.jpg". I want people to download it via download.php, with a different name (like "filetodownload.jpg"), without renaming the original file.
Sure, use a Content-disposition header
header('Content-Disposition: attachment; filename="filetodownload.jpg"');
if you wish to provide a default filename, but not automatic download, this seems to work.
header('Content-Disposition: filename="filetodownload.jpg"');
Sure you can, just try something like this:
$original_filename = '4324ffsd34.jpg';
$new_filename = 'my_new_filename_is_detailled.jpg';
// headers to send your file
header("Content-Type: application/jpeg");
header("Content-Length: " . filesize($original_filename));
header('Content-Disposition: attachment; filename="' . $new_filename . '"');
// upload the file to the user and quit
readfile($original_filename);
exit;
Hope it helps!
There is also another way if you are using html5
Download
Cheers :3
Nothing wrong with the above but I had to add:
ob_clean();
flush();
before readfile
otherwise I can not open the download jpg/png file
Download

PHP force download, Not working with variables

When
header('Content-disposition: attachment; filename=1330554893-COVER.jpg');
header('Content-type: jpeg');
readfile('watermarked/1330554893-COVER.jpg');
Is run in a file for example "testdownload.php" It downloads the image
"watermarked/1330554893-COVER.jpg"
and names it
"1330554893-COVER.jpg"
But when I try make the code dynamic to download different files.
header("Content-disposition: attachment; filename={$newFileName}");
header("Content-type: jpeg");
readfile("{$findFile}");
where
$newFileName = "1330554893-COVER.jpg" and $findFile = "watermarked/1330554893-COVER.jpg"
It downloads an image "1330554893-COVER.jpg" but it cannot be opened and I get an error "Windows Photo Viewer can't open this picture because eaither Photo Viewer doesn't support this file format"
Thanks for helping :)
Allrite then, don't use readfile(), try echo file_get_contents after the headers!

how to download the video using php script

In my program I want to add a download option to download the currently straming video. I tried this code:
$psp = "Tom_20_amp__20Jerry_20race-1.flv";
header("Content-type:application/octet-stream");
header("Content-Disposition:attachment;filename=$psp");
But I get this error:
"C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\Tom_20_amp__20Jerry_20race-1-5.flv" is not a valid FLV file.
the video streaming properly. please guide me
Change you're header from :
header("Content-type:application/octet-stream");
To :
header("Content-type: video/flv");
Then you can do :
header("Content-Disposition:attachment;filename=\"$psp\"");
//allways a good idea to let the browser know how much data to expect
header("Content-length: " . filesize($psp) . "\n\n");
echo file_get_contents($psp); //$psp should contain the full path to the video
If you are looking to allow files to be downloaded instead of streamed then something like this should work. You will obviously need to change the paths.
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="download.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
EDIT
In your case it will be something like this.
// We'll be outputting a video
header('Content-type: video/flv');
// It will be called video.flv
header('Content-Disposition: attachment; filename="video.flv"');
// The PDF source is in original.flv
readfile('original.flv');

How do I pop up a download prompt?

I am using this to put the contents to a file
file_put_contents('abc.txt', $text);
I need to have a pop up for the user after this to save/download the file
how would I do that
This will give the user a download prompt:
<?php
header('Content-type: text/plain');
// What file will be named after downloading
header('Content-Disposition: attachment; filename="abc.txt"');
// File to download
readfile('abc.txt');
?>
The manual on fpassthru() has a complete example.
Use the Content-Disposition header:
header('Content-Disposition: attachment; filename="abc.txt"');
readfile('abc.txt');
Be sure to send the appropriate Content-Type header as well.
You have to pass the right headers:
header("Content-disposition: Atachment");

Downloading a file with a different name to the stored name

Is it possible to let your user download a file with a different name?
For example, there is a file called "4324ffsd34.jpg". I want people to download it via download.php, with a different name (like "filetodownload.jpg"), without renaming the original file.
Sure, use a Content-disposition header
header('Content-Disposition: attachment; filename="filetodownload.jpg"');
if you wish to provide a default filename, but not automatic download, this seems to work.
header('Content-Disposition: filename="filetodownload.jpg"');
Sure you can, just try something like this:
$original_filename = '4324ffsd34.jpg';
$new_filename = 'my_new_filename_is_detailled.jpg';
// headers to send your file
header("Content-Type: application/jpeg");
header("Content-Length: " . filesize($original_filename));
header('Content-Disposition: attachment; filename="' . $new_filename . '"');
// upload the file to the user and quit
readfile($original_filename);
exit;
Hope it helps!
There is also another way if you are using html5
Download
Cheers :3
Nothing wrong with the above but I had to add:
ob_clean();
flush();
before readfile
otherwise I can not open the download jpg/png file
Download

Categories