Reputation: 37
I have a variable: $Name = "name of the file". Now I download a file and store in it with that name and its extension. I used cURL.
$Name = "name of the file"
$fp = fopen ('download/$Name.zip' , 'w+');
$ch = curl_init($downurl);
But this didn't work. It saved a file named $Name.zip I want it to be saved as "name of the file.zip" in download folder.
I am learning php. Please help me. Thanks!
Upvotes: 0
Views: 58
Reputation: 9583
change
$fp = fopen ('download/$Name.zip' , 'w+');
to
$fp = fopen ("download/$Name".".zip" , 'w+');
you'll also need to set some header info if you wish to output the file rather than just dump its contents
Header("Content-type: archive/zip");
Header("Content-Disposition: attachment; filename=download.zip");
Upvotes: 0
Reputation: 3874
Use double quotes in the fopen
call:
$fp = fopen ("download/$Name.zip" , 'w+');
Interpolation of variables doesn't work if you surround the string in single quotes, it has to be double quotes. You can read more about variable interpolation on Wikipedia.
Upvotes: 2