1

我正在向我的网站添加文件上传系统,但我似乎无法让文件链接与生成的文件名相匹配。我在文件名的前面添加了一个时间函数以使其唯一(它根据时间生成一个数字)。它确实这样做了,但由于某种原因,该唯一名称没有保存在数据库中。有人可以帮我解决这个问题吗?

//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';
4

1 回答 1

0

我明白现在发生了什么。对评论感到抱歉。您需要将$target变量保存在数据库中。发布的变量与目标不匹配。因此,在$file您的 SQL 语句中,您可能会想要$target。这应该给你文件的名称,但没有它看起来像的扩展名。

于 2013-04-22T21:14:47.140 回答