-1

我是 php 和 mysql 的新手。我创建了一个用于上传文件的 php 页面,这些文件保存到我的本地驱动器。在另一个页面中,当用户选择一个选项时,与该选项相关的文件以表格格式显示。一列将链接到本地​​驱动器中的文件。在这里我成功了。问题是当单击文件超链接时没有显示任何内容。但是当我复制文件的地址链接并粘贴到新窗口中时,它正在打开。请帮助我,我被困了 2 周。为了进行实验,我创建了简单的 php 文件只是为了查看超链接的工作。但没有成功。我将在这里粘贴我使用过的路径

<?php echo "<a href=`file:///C|/Inetpub/wwwroot/help.gif' >hi</a>";?>-----not worked
<?php echo "<a href=http://www.google.com>hi</a>";?> ------ working.

如果文件保存为 php 文件,即使“”标签也不起作用.....我正在使用 ISp 服务器。我的 php 文件保存在“C:\Inetpub\wwwroot\phpsample”路径中,请帮我找到解决方案

----我的原始代码----

<form  action="http://localhost/phpsample/upload/upload2.php" method='post'enctype='multipart/form-data'>
Instrument:<select name="flist">
  <option>select</option> 
  <option>gt1</option>
  <option>gt2</option>
  <option>gt3</option>
  <option>gt4</option>
</select>
</br>
Date: <input type="date" name="fdate" /></br>
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" />
</form>
<?php


global $dest;
global $name;

$dest='E:\divya';
$name=$_FILES["file"]["name"];
echo $dest;

move_uploaded_file($_FILES["file"]["tmp_name"],"$dest/$name");

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("upload_db", $con);

mysql_query("INSERT INTO upload_tb (Instrument, date_upload, filename)
VALUES('$_POST[flist]','$_POST[fdate]','$name')");
mysql_close($con);
?>
</body>
</html>

----我从表中下载文件的原始代码----

<form  action="http://localhost/phpsample/display/display.php" method='post'enctype='multipart/form-data'>
Instrument:
  <select name="flist">
    <option>select</option>
    <option>gt1</option>
    <option>gt2</option>
    <option>gt3</option>
    <option>gt4</option>
  </select>
</br>
Date: 
<input type="date" name="fdate" /></br>

<input type="submit" />
</form>
<?php

echo $_POST['fdate'];
echo $_POST['flist'];

$path='file:\\\C:\\Inetpub\\wwwroot\\phpsample\\display\\NewTextDocument.txt';


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("upload_db", $con);


$result = mysql_query("SELECT * FROM upload_tb  WHERE Instrument='$_POST[flist]'");
echo "<table border='1'>
<tr>
<th>Slno</th>
<th>Name</th>
<th>comment</th>
</tr>";
fopen("c:\Inetpub\wwwroot\phpsample\display\NewTextDocument.txt","r");
while($row = mysql_fetch_array($result))
  {
    $filename=$row['filename'];
echo $filename;
  echo "<tr>";
  echo "<td>" . $row['Instrument'] . "</td>";
  echo "<td>" . $row['date_upload'] . "</td>";
  echo "<td>"."<a href= $path>". $row['filename'] ."</a>"."</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>
</body>
</html>
4

1 回答 1

1

将此脚本放入与upload2.php相同的文件夹中的download.php中,然后调用它

http://localhost/phpsample/upload/download.php?file=FILE

FILE上传的文件名在哪里。

<?php
$con = mysqli_connect("localhost","root","", "upload_db");
if (!$con) die('Could not connect: ' . mysqli_connect_error());

$name = $_GET['file'];
$query_filename = mysqli_real_escape_string($dbh, $name);

$src = 'E:\divya';

$data = mysqli_query($con, "select filename from upload_tb where filename = '$query_filename'");
if (mysqli_num_rows($data) ! 1) die ('File not uploaded: ' . htmlentities($name));

$path = "$src/$name";
http_send_content_disposition($name);
$type = mime_content_type($path);
http_send_content_type($type);
http_send_file($path);
exit;
?>
于 2012-08-11T05:33:16.903 回答