Reputation: 857
i am trying to create a dynamic link. $path="uploads/" and $fileName="Data Communication and Networking.pdf" which is retrieved from database. But the link gets created with href="upload/Data" ignoring the " Communication and Networking.pdf" part. How to add $fileName with spaces between the content.
$message=$row["message"];
$fileName=$row["filename"];
$date=$row["date"];
echo "<tr>";
echo "<td>".$Serial."</td>";
echo "<td>".$message."</td>";
echo "<td><a href=".$path.$fileName.">Download</a></td>";
echo "<td>".$date."</td>";
echo "</tr>";
$Serial++;;
Upvotes: 2
Views: 513
Reputation: 1
$path="/path";
$filename="/file with space.name";
echo "<td><a href=".$path.$fileName.">Download</a></td>";
Will output:
`<td><a href=/path/file with space.name>Download</a></td>`
So you need to put the path between the quotes like this:
$path="/path";
$filename="/file with space.name";
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
Upvotes: 0
Reputation: 15257
You can replace any space with %20
$CompletePath = str_replace(" ", "%20", $path . $fileName);
echo "<td><a href=" . $CompletePath . ">Download</a></td>";
//uploads/Data%20Communication%20and%20Networking.pdf is a valid URL
Upvotes: 1
Reputation: 16436
href
value must consist in quotes. Place single quotes around your value.change your href
as below:
echo "<td><a href='".$path.$fileName."'>Download</a></td>";
Upvotes: 2