Jump to content

help with hyperlinks


bratsmasher
Go to solution Solved by lemmin,

Recommended Posts

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

.

 

Link to comment
Share on other sites

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 by computermax2328
Link to comment
Share on other sites

@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 by bratsmasher
Link to comment
Share on other sites

%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 by BradlySpicer
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by bratsmasher
Link to comment
Share on other sites

  • Solution

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>";
Link to comment
Share on other sites

 

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 by bratsmasher
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.