我正在将文件上传系统添加到我的网站,我似乎无法获取文件链接以匹配生成的文件名。我在文件名的前面添加了一个时间函数,使其唯一(它根据时间生成一个数字)。它确实这样做,但由于某种原因,该唯一名称未保存在数据库中。有人可以帮我解决这个问题吗?
//This is the directory where images will be saved
$target = "files/";
$target = $target. time(). basename( $_FILES['photo']['name']);
echo $target;
//postThis gets all the other information from the form
$tfid=$_POST['tfid'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$hca=$_POST['hca'];
$file=($_FILES['photo']['name']);
//Writes the information to the pic table
mysql_query("INSERT INTO pic
(tfid, file)
VALUES ('$tfid', '$file')")
or die(mysql_error());
ECHO "<strong>pic table has been saved.<br></strong>";
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "<strong>The file has been uploaded</strong>";
}
else {
//Gives an error if its not
echo "<strong>Sorry, there was a problem uploading your file.</strong>";
}
echo '<br>';
require 'insertbuttons.php';
答案 0 :(得分:0)
我看到现在发生了什么。对此评论感到抱歉。您需要在数据库中保存$target
变量。发布的变量与目标不匹配。因此,如果您在SQL语句中有$file
,则可能需要$target
。这应该给你文件的名称,但没有扩展它看起来像。