Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 向上载的文件和数据库添加时间_Php_Mysql - Fatal编程技术网

Php 向上载的文件和数据库添加时间

Php 向上载的文件和数据库添加时间,php,mysql,Php,Mysql,我正在为我的网站添加一个文件上传系统,我似乎无法获得与生成的文件名匹配的文件链接。我在文件名前面添加了一个时间函数,使其唯一(它根据时间生成一个数字)。它确实可以这样做,但由于某种原因,该唯一名称不会保存在数据库中。有人能帮我弄清楚吗 //This is the directory where images will be saved $target = "files/"; $target = $target. time(). basename( $_FILES['photo']['na

我正在为我的网站添加一个文件上传系统,我似乎无法获得与生成的文件名匹配的文件链接。我在文件名前面添加了一个时间函数,使其唯一(它根据时间生成一个数字)。它确实可以这样做,但由于某种原因,该唯一名称不会保存在数据库中。有人能帮我弄清楚吗

//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';
//这是保存图像的目录
$target=“files/”;
$target=$target。时间()。basename($_文件['photo']['name']);
echo$target;
//postThis从表单中获取所有其他信息
$tfid=$_POST['tfid'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$hca=$_POST['hca'];
$file=($_文件['photo']['name']);
//将信息写入pic表
mysql_查询(“插入pic
(tfid,文件)
值('$tfid','$file'))
或者死(mysql_error());
ECHO“图片表已保存。
”; //将照片写入服务器 如果(移动上传的文件($文件['photo']['tmp\u name'],$target)) { //告诉你一切是否正常 echo“文件已上载”; } 否则{ //如果不是,则给出一个错误 echo“很抱歉,上载文件时出现问题。”; } 回声“
”; 需要“insertbuttons.php”;
我知道现在发生了什么。对这些评论感到抱歉。您需要在数据库中保存
$target
变量。发布的变量与目标不匹配。因此,如果SQL语句中有
$file
,则可能需要
$target
。这应该是文件名,但没有扩展名。您在这里写的内容会在上传文件时为文件名添加时间?看起来它不会这样做。更像是它在前面添加了一个随机生成的数字。我将编辑我的帖子以反映这一点。您在这里为
$target
变量提供的代码似乎不正确。看起来它会随着时间将您的文件移动到文件夹中。它会在上载的文件名中添加一个数字。但是,如果使用错误的方法,正确的方法是什么?我希望将文件移动到文件夹中。从那里,另一个页面创建了一个指向它的超链接,但它创建的链接末尾没有数字。非常感谢。这就成功了。我还意识到我的链接中嵌入了第二个“file/”。“我把它们拿出来,现在它很好用了。”凯勒说,“好极了。再次对之前的评论表示抱歉。我问了这么多这样的问题,我的大脑都快发疯了!