$imageURL = 'http://www.cnsnews.com/sites/default/files/images/OBAMA-AP%20PHOTO_8.jpg';
$imageInfo = pathinfo($imageURL);
$imageName = clean(basename($imageURL,'.'.$imageInfo['extension']));
$fileName = $imageName.'.'.$imageInfo['extension'];// file name
$content = file_get_contents($imageURL);
file_put_contents(UPLOAD_DIR.$fileName, $content);
$product_file = UPLOAD_DIR.$fileName;
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
return preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
}
.. although almost all urls I've tried work fine except this one, probably because of the special chars in OBAMA-AP%20PHOTO_8.jpg
? even though I'm cleaning it?
The image doesn't get downloaded.