Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:56:04+00:00 2026-06-07T05:56:04+00:00

Sorry if this is something stupid but just looking for some genuine help. Struggling

  • 0

Sorry if this is something stupid but just looking for some genuine help. Struggling with this.

I have a HTML script that uploads a file called minegem.html which when submitted calls minegem.php This script uploads the data from the form into the table, uploads a file to a directory, and gives the user a table to view said data. It all works quite nicely.

<?php

//define variables to be used
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';

$database = 'minetech';
$table = 'minegem';
$directory = 'uploads/minegem/';

//This gets all the other information from the form
$name=$_POST['docname'];
$version=$_POST['docver'];
$date=$_POST['docdate'];
$type=$_POST['doctype'];
$author=$_POST['docauth'];

//target directory is assigned
$target = $directory;
$target = $target . basename( $_FILES['uploaded']['name']) ; 

//if everything is ok upload the file
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}

//connect to sql
$con = mysql_connect("$db_host","$db_user","$db_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//connect to database
mysql_select_db("$database", $con);

//insert data from form to database
$sql="INSERT INTO $table (DocName, DocVer, DocDate, DocType, DocAuth, DocLoc)
VALUES
('$name','$version','$date','$type','$author','$target')";

//confirm data entry
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo " and new record added. How cool is that.";


//the following script displays the data for test purposes


//this script will show table data
//retrieve tables values
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
    die("Query to show fields from table failed");
}

//build table and define headings
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Version</th>
<th>Upload Date</th>
<th>Type</th>
<th>Uploader</th>
<th>Location</th>
</tr>";


// printing table rows
while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
echo "<td>" . $row['DocName'] . "</td>";
echo "<td>" . $row['DocVer'] . "</td>";
echo "<td>" . $row['DocDate'] . "</td>";
echo "<td>" . $row['DocType'] . "</td>";
echo "<td>" . $row['DocAuth'] . "</td>";
echo "<td>" . $row['DocLoc'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_free_result($result);

//close connecition to database
mysql_close($con)
?>`

Both of the files are located in C:/wamp/www/ so when I run them via web browser it shows as localhost/minegem.php

I have a final script which will be the one I actually run to show the end user the results.

<?php

//define variables to be used
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '';

$database = 'minetech';
$table = 'minegem';
$type = 'Guideline';

//connect to sql
$con = mysql_connect("$db_host","$db_user","$db_pwd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

//connect to database
mysql_select_db("$database", $con);

//this script will show table data
//retrieve tables values
$result = mysql_query("SELECT * FROM $table
WHERE DocType='Guideline'");
if (!$result) {
    die("Query to show fields from table failed");
}

//build table and define headings
echo "<table border='1'>
<tr>
<th>Document Name</th>
<th>Version</th>
</tr>";


// 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='.urlencode($docloc).'>'.$docname.'</a></td>';
echo "<td>$docver</td>";
echo "</tr>";


}
echo "</table>";


mysql_free_result($result);

//close connecition to database
mysql_close($con)

?>

My first table shows the file location as uploads/minegem/test document.pdf
The second table that display that as a link shows in the address bar http://localhost/uploads%2Fminegem%2Ftest+document.pdf
And on the page is says
The requested URL /uploads/minegem/test+document.pdf was not found on this server.

I assume this is a stupid file structure problem but its crucial. I will end up putting this on a server so being able to store the complete file patch and recall that as a link would be great. I’m hoping someone can help point me in the right direction with setting up correct file structures. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:56:05+00:00Added an answer on June 7, 2026 at 5:56 am

    Use rawurlencode instead. This replaces the space with a %20 and not a plus sign.

    The + is used for transfer of data, the %20 for URLs that are displayed for clicking on. Although you can always user %20 for data transfer, you can only sometimes use +, if browsers incorrectly support it. So stick with rawurlencode.

    Also, rawurlencode the basename part only before insertion into the database. This leaves the path not urlencoded. I don’t think this but is breaking your code, but it’s a lot neater.


    Answering Q) how to rawurlencode just the basename.

    A) Just store the basename in the database. You know the path ($directory) and so you can use move_uploaded_file(…, $directory . $target); and then when outputting the file location, use a href=”http://localhost/’.$directory.rawurlencode($target) . ‘”


    But a couple of other “issues” that are also very important.

    1. When you output the text to screen for display, make sure you use httpspecialchars() on it.

      [a href=”http://localhost/’.$directory.rawurlencode($target).'”]’.$directory.httpspecialchars($target).'[/a] // Replace square brackets with angle brackets – can’t enter angle brackets here.

    2. When saving to database at a minimum use “mysql_real_escape_string” to make it safe for entering into the database. But is it STRONGLY recommended to use PDO or mysqli (mysql functions are being depreciated, where as PDO and mysqli are both safer to use by design)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this sounds stupid but I'm really new to LiftWeb and just struggling
Sorry if this is a stupid question, but it's something that I'm curious about.
I'm really sorry to have to ask this, but I clearly don't understand something
sorry if i'm doing something monumentally stupid, but I can't get this IF statement
Sorry this might be a very stupid question. But I did have bug with
this may be a stupid question: I currently have some VM arguments that my
Sorry if this question will sound stupid, but I'm just starting to learn C++
EDIT: It does work (sorry). Something in this script is causing it to stop
Sorry this is a basic question, but all my research just barely missed answering
Sorry if this question seems stupid, but it's stumped me for a couple days,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.