bratsmasher Posted April 15, 2013 Share Posted April 15, 2013 Hello: I am having a problem with making hyperlinks to link to the right location. What I want it to do is just add the filename to the end of the first part (C:\php\website\files\insertfilenamehere.jpg). instead, I get something like this: file:///C:/php/website%0Ciles/%7Bwin2010filebutton.png%7D. Why are % signs and more slashes showing up in my file path? Could anyone point me in the right direction as to why they are not showing up correctly? I would appreciate any help that can be given. while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo $row['file']; $inf= $row['file']; echo "<tr><td>"; echo $row['tfid']; echo "</td><td>"; echo $row['lname']; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo "<a href=\"C:\php\website\files\{$inf}\">Link</a>"; echo "</td></tr>"; } echo "</table>"; . Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/ Share on other sites More sharing options...
computermax2328 Posted April 15, 2013 Share Posted April 15, 2013 (edited) Take the "C:" out of the hyperlink and see what happens. It looks like your computer is adding the "%" in your localhost to add spaces. Also your link should be.. echo "<a href='php/website/files/$inf'>Link</a>"; If that doesnt work you need to add concatenations to your link before and after the $inf. Edited April 15, 2013 by computermax2328 Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424882 Share on other sites More sharing options...
bratsmasher Posted April 15, 2013 Author Share Posted April 15, 2013 (edited) @computermax2328: I tried taking out the C:. I am still getting the % signs in my hyperlink. Is there anything else I can do to fix it? Also, I am not sure what I am doing is even possible. By creating a link to a file on my local computer, can a person remoting into the machine click on those links to open the specific image/file? Edited April 15, 2013 by bratsmasher Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424884 Share on other sites More sharing options...
computermax2328 Posted April 15, 2013 Share Posted April 15, 2013 Are you running WAMP or anything on your localhost? Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424887 Share on other sites More sharing options...
computermax2328 Posted April 15, 2013 Share Posted April 15, 2013 (edited) And the answer to your question is no. Because if you send them the web page their computer will be looking for the file in a file path that does not exist on their computer. Edited April 15, 2013 by computermax2328 Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424888 Share on other sites More sharing options...
BradlySpicer Posted April 15, 2013 Share Posted April 15, 2013 (edited) %20 means spacebar. If you have a space in any folder names or files replace them with "_" E.g The Cat Folder would be The_Cat_Folder while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo $row['file']; $inf= $row['file']; echo "<tr><td>"; echo $row['tfid']; echo "</td><td>"; echo $row['lname']; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo "<a href=\"/files/{$inf}\">Link</a>"; echo "</td></tr>"; } echo "</table>"; try this Edited April 15, 2013 by BradlySpicer Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424890 Share on other sites More sharing options...
bratsmasher Posted April 15, 2013 Author Share Posted April 15, 2013 And the answer to your question is no. Because if you send them the web page their computer will be looking for the file in a file path that does not exist o their computer. I am not running WAMP or any sort of web server. Due to certain restrictions, I can only use the PHP 5.4 development server for this project. The idea is to create a filing system using a web GUI to organize images, be able to run a search for specific records, and then create a link to send them to the image on the local machine. I am all ears If you have another method to do so. Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424893 Share on other sites More sharing options...
bratsmasher Posted April 15, 2013 Author Share Posted April 15, 2013 (edited) Thank you to all of you who have responded to this plea for help. Every one of my folder/files are a single word with no spaces (website,php, image, etc). The browser is also adding random things to the link. It should look like this:C:/php/website/Files/CFRH.png Instead, I get this: http://localhost:8000/php/website%0Ciles/%7BCFRH.png%7D It changes the word files to Ciles, and encapsulates the file name with 7B and 7D. Does anyone know why this is occuring? Edited April 15, 2013 by bratsmasher Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424896 Share on other sites More sharing options...
Solution lemmin Posted April 15, 2013 Solution Share Posted April 15, 2013 Your URL is being encoded -- probably by the browser; since it is, in fact, a URL, there shouldn't be a problem. I think the problem you are having is actually with your URL BEFORE it is URL-encoded. Notice the "%7D" at the end of the example you gave? That shouldn't be there. That is the encoded "}" character. Computermax2328 suggested you remove the curly braces and I think they might actually be your only problem. Did you try his solution? Another solution that may be more portable would be to concatenate the filename inside your link: echo "<a href='php/website/files/".$inf."'>Link</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424900 Share on other sites More sharing options...
bratsmasher Posted April 15, 2013 Author Share Posted April 15, 2013 (edited) Your URL is being encoded -- probably by the browser; since it is, in fact, a URL, there shouldn't be a problem. I think the problem you are having is actually with your URL BEFORE it is URL-encoded. Notice the "%7D" at the end of the example you gave? That shouldn't be there. That is the encoded "}" character. Computermax2328 suggested you remove the curly braces and I think they might actually be your only problem. Did you try his solution? Another solution that may be more portable would be to concatenate the filename inside your link: echo "<a href='php/website/files/".$inf."'>Link</a>"; Thanks man! You just solved my problem. It seems like it is a combination of issues that made this one up. The other thing I just realized is that the file path starts from the web site folder, not C:. Just one more quick question: is there a simple way to convert a file name with spaces into a name without them? I would assume you would have to pull the name into an array and then search for the spaces character by character. Am I on the right track? Edited April 15, 2013 by bratsmasher Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424904 Share on other sites More sharing options...
lemmin Posted April 15, 2013 Share Posted April 15, 2013 If you are naming (or renaming) these files in PHP you can change the name based on a simple character translation: http://us1.php.net/manual/en/function.strtr.php $filename = strtr($filename, ' ', '_'); Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424908 Share on other sites More sharing options...
bratsmasher Posted April 15, 2013 Author Share Posted April 15, 2013 Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/276978-help-with-hyperlinks/#findComment-1424911 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.