2

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++;;
1
  • you can try using urlencode() Commented May 16, 2018 at 11:54

3 Answers 3

2

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>";
Sign up to request clarification or add additional context in comments.

1 Comment

glad to help @CoolCompiler
1

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

Comments

0
$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>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.