I have a php file upload script which returns a json response. The issue is the url of the response contains odd characters.
I get a response that has \ / between the directories instead of just / or \ /\ / after the http: instead of just //
So I am getting this. http:\ / \ /www.mywebsite.com\ /uploads\ /myfile.jpg
But I need it to look like this. http://www.mywebsite.com/uploads/myfile.jpg
Based on my code below any thoughts on what I need to change?
<?php
header('Content-Type: application/json');
if(isset($_POST['album_name']))
{
$dir_name = $_POST['album_name'];
}
$json = array();
if(file_exists('uploads/'.$dir_name))
{
$handle = opendir('uploads/'.$dir_name);
while(false !== ($file = readdir($handle)))
{
if($file != '.' && $file != '..')
{
$url= 'http://www.'.$_SERVER['SERVER_NAME'].'/uploads/'.$dir_name.'/'.$file;
$data = array($type,$url);
array_push($json,$data);
}
}
}
echo json_encode($json);
?>