1

I have a table being displayed that converts a file uploaded location (DocLoc) into a hyperlink. However, because the filename has spaces in it, the hyperlink drops them off. If I display the column docloc it shows:

uploading/minegem/GUI-MGEM-001 Bullet Programming.pdf

However, when I click the hyperlink I get

uploading/minegem/GUI-MGEM-001

How can I have the hyperlink add the rest of the filename so I can open the file from the link?

// Printing table rows
while($row = mysql_fetch_array($result))
{
    $docname=$row['DocName'];
    $docver=$row['DocVer'];
    $doctype=$row['DocType'];
    $docloc=$row['DocLoc'];

    echo "<tr>";
    echo "<td><a href=/uploading/$docloc>$docname</a></td>";
    echo "<td>$docver</td>";
    echo
    echo "</tr>";
}
echo "</table>";

Sorry if this is stupid, I have done a bit of googling and reading around here and I'm struggling. I only started learning PHP, MySQL, and HTML about three days ago.

1
  • 1
    Its a good trick to learn early on to look carefully at the source code of your HTML output, if you are attuned to what is/not valid HTML then you would have perhaps spotted the reason for the error, just sayin'. Commented Jul 7, 2012 at 8:57

1 Answer 1

2

Encode the URL using urlencode:

echo '<td><a href="/uploading/'.urlencode($docloc).'">'.$docname.'</a></td>';
Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget the quotes around the URL value for the HREF attribute. <a href="" />

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.