I use this code to upload a file to my server using HTTP POST:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
"upload" => '@' . $filepath
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$curl_result = curl_exec($ch);
This code works when $ filepath does not contain spaces. However, this is possible. When I check the path with spaces, I get a curl error "Failed to create shaping data."
The curl guide does not say what to do, all it gives me are unix files without spaces. I tried following http://curl.haxx.se/mail/archive-2006-01/0079.html , but that didn't help me either:
"upload" => '"@' . $filepath . '"'
"upload" => '@"' . $filepath . '"'
Does anyone have an idea?
source
share