I'm calling a PHP script via AJAX that saves a remote image locally (via Mapbox API). Everything works great, except for the result
includes a 'space' (filename.jpg[space]
) at the end of the string.
Javascript:
var mapboxUrl = 'https://api.mapbox.com/v4/motioncrafter.96d11990/' + longitude + ',' + latitude + ',11/1280x720@2x.jpg80?access_token=pk.eyJ1IjoibW90aW9uY3JhZnRlciIsImEiOiJjaWg2dHJvM2YwNndudjJrdGI2amUzdnlyIn0.oN201-rjUC4DHhz7QhGJRA';
$.ajax({
type: "POST",
url: "../../php/map.php",
data: {
map: mapboxUrl,
},
success: function(result) {
$('.video_map').val(result);
}
});
PHP:
<?php
$mapboxUrl = $_POST["map"];
$path = "../images/user-maps/";
$imageFile = $path . "map_wide_" . rand(10000, 99999) . time() . ".jpg";
$ch = curl_init($mapboxUrl);
$fp = fopen($imageFile, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo $imageFile;
?>
Any idea why this space is showing up?