Reputation: 98
I am trying to download a file(s) that will have spaces in the name. the script works fine for names without spaces but not if there is a space. I understand why this happens but not how to fix the issue. I have spent the better part of a day searching the web for a answer with out any luck so far. So here is my question. How can I change this file to enable it to read the how name including the spaces.
echo"<a href=http://www.site.com/uploads/".$row['att'] ." download=".$row['att'].">Download attachment</a>";
Upvotes: 1
Views: 73
Reputation: 98
Thanks for the answers everyone working great now. for reference here is what it looks like before and after.
Before
echo"<a href=http://www.site.com/uploads/".$row['att'] ." download=".$row['att'].">Download attachment</a>";
After
echo'<a href="http://www.sire.com/uploads/'.$row['att'] .'" download="'.$row['att'].'">Download attachment</a>"';
I had the quotes all mixed up and in the wrong places.
Upvotes: 0
Reputation: 12966
I'm not sure what that "download" attribute is for, but you should look into urlencode and htmlspecialchars:
echo '<a href="http://www.site.com/uploads/'. urlencode($row['att']) .'" download="'.urlencode($row['att']).'">Download attachment</a>";
Upvotes: 0
Reputation: 33447
You need to quote the attribute. Also, since it's going into html, it should be escaped.
echo '<a href="' . htmlspecialchars($url) . '">Link</a>';
Upvotes: 3
Reputation: 324650
HTML attributes need quotes. Otherwise they are delimited by space.
echo "<a href=\"http://......../\">Download</a>";
Alternatively, you can correctly encode it as %20
, but still, put quotes around your attributes...
Upvotes: 2