对不起,如果这是愚蠢的,但只是在寻找一些真正的帮助。正在为此苦苦挣扎。
我有一个 HTML 脚本,它上传一个名为的文件minegem.html
,当提交调用时,minegem.php
该脚本将表单中的数据上传到表中,将文件上传到目录,并为用户提供一个表来查看所述数据。这一切都很好。
<?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)
?>`
这两个文件都位于,C:/wamp/www/
所以当我通过网络浏览器运行它们时,它显示为localhost/minegem.php
我有一个最终脚本,它将是我实际运行以向最终用户显示结果的脚本。
<?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)
?>
我的第一个表格将文件位置显示为uploads/minegem/test document.pdf
第二个表格显示为链接显示在地址栏中http://localhost/uploads%2Fminegem%2Ftest+document.pdf
并且在页面上说
The requested URL /uploads/minegem/test+document.pdf was not found on this server.
我认为这是一个愚蠢的文件结构问题,但它至关重要。我最终会将它放在服务器上,以便能够存储完整的文件补丁并记住作为链接会很棒。我希望有人可以通过设置正确的文件结构来帮助我指出正确的方向。谢谢。