Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl with empty space url

Tags:

php

curl

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;
like image 825
Jinbom Heo Avatar asked Dec 04 '22 19:12

Jinbom Heo


1 Answers

$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;
like image 73
DhruvPathak Avatar answered Dec 10 '22 10:12

DhruvPathak