Is there a way to display the directory link using PHP?

I have a Word document saved in my folder, and its name is already in the database. I want to display this document from the folder using PHP. When someone clicks on the link, the entire document should appear on the front end.

$sql = "SELECT * FROM user WHERE city LIKE '%".$term."%'"; 
$r_query = mysql_query($sql); 

while ($row = mysql_fetch_array($r_query)){  
echo 'First Name: ' .$row['fname'];  
echo '<br /> Resume: <a href="' . $row['resume'] . '">View Document</a>'; 

This code will only print the resume name stored in the database. I want to make the resume name a clickable link that, when clicked, displays the entire document.

Answer №1

In response to your comment, it is recommended that you include the folder path in an anchor tag.

$path = __DIR__ . "/../resume_folder/";
echo $path;

If $path is accurate, use the following code:

while ($row = mysql_fetch_array($r_query)){  
  echo 'First name: ' .$row['fname'];  
  echo "<a href='$path.{$row['resume']}'>View Resume</a>";
}

I hope this solution solves your issue :)

Answer №2

Experiment with this method:

echo '<br /> <a href = "<?php echo path_url().$information['cv'];?>"> Curriculum Vitae </a>';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery AJAX to Transfer Data to a PHP Script

There is a div element with a data-id attribute. The goal is to use jQuery to detect when this div is clicked and then send or store the corresponding data-id value in a PHP file. However, the code provided raises an error when trying to obtain the data-id ...

Include CakePHP named parameters in the URL when selecting from a list

If I have a selection list like the one below: <select name='languages'> <option value='german'>German</option> <option value='english'>English</option> </select> How can I use Jav ...

Retrieve the id of an element from a JSON object

Dealing with quotes, single or double, can sometimes pose a challenge. I am working on a JavaScript function that sends data to a PHP file and receives a JSON response. Everything seems to be functioning correctly, except for the part where I need to out ...

Utilizing Laravel to send an ajax request to a controller

I am encountering a strange issue with the response from my ajax request. The controller's method below is supposed to return an ID: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; //use App\Http&bsol ...

Adding a prefix to a Smarty variable

Seeking a solution to add a string in front of a Smarty variable. A dynamic form has element names like input-1 (where 1 represents the id of the setting/field). I attempted to use {capture}{/capture}, but it seems to only work the first time due to the f ...

A collection of items that mysteriously affix themselves to the top of the page as

Unique Context In my webpage, I have a specific div element with the CSS property of overflow: auto. Within this scrolling div, there is structured content like this: <h3>Group A</h3> <ul> <li>Item 1</li> <li>I ...

Creating PHP output and storing it in a file in a format that is not human-readable

I have received a response from the SOAP client and I am trying to format this output in my PHP code. My goal is to write this formatted output into a file that is readable for users. However, when writing to the file, there are no spaces or new lines in ...

PDO SQL Query Not Restricting

After executing a query to the database with LIMIT 10, I'm not getting any results. It seems like there might be an issue with my code. Can anyone spot the mistake? Here's the code snippet that I believe is causing this unexpected behavior. I&ap ...

adding a collection of file names from a directory into a mysql database

I have a task where I need to fetch a list of filenames from a folder and then insert them into a mysql database using php. However, when I try inserting the filenames into the database, it seems to be stuck in an infinite loop. Even though there are only ...

PHP Partial Caching refers to the practice of storing and

I am looking to partially cache some php files. For example: <? echo "<h1>", $anyPerdefinedVarible, "</h1>"; echo "time at linux is: "; // starting not been cached section echo date(); //end of partial cach echo "<div>goodbye $footerV ...

The PHP script invoked by ajax is unable to run the start_session() function

When I run script A, it starts the session and initializes some variables. Afterwards, the script triggers an ajax call that calls script B: $("#galleryContent").load("B.php", {op : 'get_thumbs' }, ...

Utilize jQuery to extract all values from the second cell of a table and store them in an array

I have a task that involves pushing numbers from text boxes into an array. These text boxes are located in the second cell of each table row, while the third cell contains a date picker. Currently, the code snippet provided retrieves all values from both ...

The Node encountered a problem connecting to MySQL and did not provide any error message

Although the problem has been resolved, I want to leave a lasting impact with this question. Thank you to everyone! update I discovered an issue in /src/mysql/index.js, within this code /* incorrect code */ MySqlConnection.connect((error) => { /* ...

Ran into a snag trying to fetch the newest files through PHP and SFTP via ssh2

#!/usr/bin/php <?php $username = "backup"; $password = "xxxxxxx"; $url = '192.168.1.100'; // Establish connection $connection = ssh2_connect($url); // Authenticate if (!ssh2_auth_password($connection, $username, $password)) ...

The condition statement checks the character length of the content from the_content() function

Looking to determine the length of Character Length in my Custom Post Type post->content. The content is being displayed with a limit of 200 words. <?php $content = get_the_content(); echo substr($content, 0, 200); ?> If the character count exc ...

Unexpected Error During Laravel Migration

Upon running php artisan migrate, I encountered the following error: My Terminal: INFO Running migrations. 2014_10_12_000000_create_users_table .................................................................................................... 3ms FAIL ...

Extracting Section Titles from INI using PHP

I've spent all night trying to perfect this code with no luck. I'm not even sure what to search for at this point. Here's the situation: I'm using PHP to parse .ini files into an HTML table. This is the code in my html file: <?php ...

Looking for a solution to replace a section of a filename in a URI using htaccess mod_rewrite? Cross-domain

I've been going through tutorials on htaccess, but every example I find seems to use an absolute URL in the rewrite. Since my site spans multiple domains, I need a solution that works across all of them. The rule I'm looking for is: Any link tha ...

What is the best approach for dynamically appending new elements to a JSON array using PHP?

I am facing an issue with the JSON below: [{"username":"User1","password":"Password"}, {"username":"User5","password":"passWord"},] The above JSON is generated using the PHP code snippet mentioned below: <?php $username = $_POST["username"]; ?>&l ...

Disabling Bootstrap Js, JQuery, and CSS in Yii2

Can anyone suggest an alternative to using bootstrap.css and bootstrap.js? I've attempted the following: 'assetManager' => [ 'bundles' => [ 'yii\bootstrap\BootstrapAsset' => [ & ...