Jinbom Heo
Jinbom Heo

Reputation: 7400

curl with empty space url

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

Answers (3)

user1006565
user1006565

Reputation:

try using urlencode('http://domain.com/hello I am good.zip'); or http://domain.com/'.urlencode('hello I am good.zip');

Upvotes: 3

DhruvPathak
DhruvPathak

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

talha2k
talha2k

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

Related Questions