Question: I have a website that allows users to upload a file. when uploading the file on another page users can download that file. the problem is if the file name has a space in it will only pick up the first work not the whole file name. i was wondering is there a way to download the file with spaces in it or an easy option might be to add underscores to the file name so that it can be downloaded. 

```
 //This is the directory where images will be saved 
 $target = "../images/avatars/"; 
 $target = $target . basename($_FILES['photoLocation']['name']);

// Check to see all fields have been completed
$photoLocation =($_FILES['photoLocation']['name']);

if (!empty($photoLocation))
{

    // Create an SQL query to add the comment
    $sql = "INSERT INTO tblPhotoUpload (photoLocation) VALUES ('$photoLocation')";

    // Connect to the database
    connect();

    // Run the query and store the result in a variable
    $result = mysql_query($sql) or die("Could not run query");

    //Writes the photo to the server 
    if(move_uploaded_file($_FILES['photoLocation']['tmp_name'], $target))

    // Close connection to the database
    mysql_close()

```

And i am displaying the file like this. 

```
while($record = mysql_fetch_array( $result )) 
 { 
 ?> 

 <tr class="row">
    <td class="cell"><a href= http://xxxxxxxxxxxxxxxxxxxxxx.com/images/avatars/<?php         echo $record["photoLocation"];?>>Download</a> </td>

```

Answer: 
i would recommend to not display image by it original name, since there alot of security problems associated with that.

a way u can do it is to encode file name and save it in extra field in database.

example

```
$sql = "INSERT INTO tblPhotoUpload (photoLocation,photourl) VALUES ('$photoLocation','".md5($photoLocation)."')";

```

and when display use phtolocation in url and make display route that to photo location.

good luck,if u need full example let me know
[str\_replace()](http://php.net/manual/en/function.str-replace.php)

$file= str\_replace(' ','\_',$file);

or in your case :

```
$target = $target . basename(str_replace(' ','_',$_FILES['photoLocation']['name']));

$photoLocation =(str_replace(' ','_',$_FILES['photoLocation']['name']));

```