Note that there are some explanatory texts on larger screens.

plurals
  1. POUploaded file won't open (incorrect directory) from table (PHP,MySQL)
    primarykey
    data
    text
    <p>Sorry if this is something stupid but just looking for some genuine help. Struggling with this.</p> <p>I have a HTML script that uploads a file called <code>minegem.html</code> which when submitted calls <code>minegem.php</code> 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.</p> <pre><code>&lt;?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 "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Version&lt;/th&gt; &lt;th&gt;Upload Date&lt;/th&gt; &lt;th&gt;Type&lt;/th&gt; &lt;th&gt;Uploader&lt;/th&gt; &lt;th&gt;Location&lt;/th&gt; &lt;/tr&gt;"; // printing table rows while($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['DocName'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DocVer'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DocDate'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DocType'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DocAuth'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['DocLoc'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysql_free_result($result); //close connecition to database mysql_close($con) ?&gt;` </code></pre> <p>Both of the files are located in <code>C:/wamp/www/</code> so when I run them via web browser it shows as <code>localhost/minegem.php</code></p> <p>I have a final script which will be the one I actually run to show the end user the results.</p> <pre><code>&lt;?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 "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Document Name&lt;/th&gt; &lt;th&gt;Version&lt;/th&gt; &lt;/tr&gt;"; // printing table rows while($row = mysql_fetch_array($result)) { $docname=$row['DocName']; $docver=$row['DocVer']; $doctype=$row['DocType']; $docloc=$row['DocLoc']; echo "&lt;tr&gt;"; echo '&lt;td&gt;&lt;a href='.urlencode($docloc).'&gt;'.$docname.'&lt;/a&gt;&lt;/td&gt;'; echo "&lt;td&gt;$docver&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysql_free_result($result); //close connecition to database mysql_close($con) ?&gt; </code></pre> <p>My first table shows the file location as <code>uploads/minegem/test document.pdf</code> The second table that display that as a link shows in the address bar <code>http://localhost/uploads%2Fminegem%2Ftest+document.pdf</code> And on the page is says <code>The requested URL /uploads/minegem/test+document.pdf was not found on this server.</code></p> <p>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. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload