5

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;

3 Answers 3

13
$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;
Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking that is a space related problem, but I was unsure. Only files with spaces in their filenames were not downloaded. Thank you.
4

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.

Comments

3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.