Reputation: 7400
there is a file, its name contain empty space. ex) hello I am good.zip
I am trying to read the file using curl.
so, the url should be like this:
http://domain.com/hello I am good.zip
but, curl can not seems to read that kind of file names. because url is not right format.
So, Is there another way to read the file using curl? Or some options that I didn't know?
server lang is php. and my curl code is below:
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
Upvotes: 5
Views: 16685
Reputation:
try using urlencode('http://domain.com/hello I am good.zip');
or http://domain.com/'.urlencode('hello I am good.zip')
;
Upvotes: 3
Reputation: 43245
$url = str_replace(" ","%20",$url); // to properly format the url
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
Upvotes: 13
Reputation: 1
Where ever there's a space
use %20
, that should do the trick, hopefully.
so it will become:
http://domain.com/hello%20I%20am%20good.zip
This will hopefully do the trick.
Hope this helps.
Upvotes: 4