Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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将带时间戳的图像名称发送到mysql_Php_Mysql - Fatal编程技术网

如何使用PHP将带时间戳的图像名称发送到mysql

如何使用PHP将带时间戳的图像名称发送到mysql,php,mysql,Php,Mysql,下面是我的代码,它将多个图像上传到一个文件夹和mysql的路径。我是全新的,所以请原谅我这么愚蠢的问题,但我不知道从哪里开始发送这个时间戳或$fileName值到mysql <?php require_once('storescripts/connect.php'); mysql_select_db($database_phpimage,$phpimage); $uploadDir = 'upload/'; if(isset($_POST['upload'])) { foreach

下面是我的代码,它将多个图像上传到一个文件夹和mysql的路径。我是全新的,所以请原谅我这么愚蠢的问题,但我不知道从哪里开始发送这个时间戳或$fileName值到mysql

<?php
require_once('storescripts/connect.php');
mysql_select_db($database_phpimage,$phpimage);
$uploadDir = 'upload/';

if(isset($_POST['upload']))
{


foreach ($_FILES as $file)
{

    $fileName = $file['name'];
    $tmpName = $file['tmp_name'];
    $fileSize = $file['size'];
    $fileType = $file['type'];

    if ($fileName != ""){
        $filePath = $uploadDir;
        $fileName = str_replace(" ", "_", $fileName);

        //Split the name into the base name and extension
        $pathInfo = pathinfo($fileName);
        $fileName_base = $pathInfo['fileName'];
        $fileName_ext = $pathInfo['extension'];

        //now we re-assemble the file name, sticking the output of uniqid into it
        //and keep doing this in a loop until we generate a name that 
        //does not already exist (most likely we will get that first try)
        do {
           $fileName = $fileName_base . uniqid() . '.' . $fileName_ext;
        } while (file_exists($filePath.$fileName));

        $result = move_uploaded_file($tmpName, $filePath.$fileName);
    }


if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$fileinsert[]=$filePath;
}
    $cat=$_POST['cat'];//this is the category the product is stored in
    $about=$_POST['about'];//this is some general information about the item
    $price=$_POST['price'];//the price of the item
    $item=$_POST['item'];//the name of the item
    $name1=basename($_FILES['image01'][$fileName]);//the file name of the first actual jpg
    $name2=basename($_FILES['image02'][$fileName]);//the file name of the sencond actual jpg
    $name3=basename($_FILES['image03'][$fileName]);//the file name of the third actual jpg
    $name4=basename($_FILES['image04'][$fileName]);//the file name of the fourth actual jpg

$query = "INSERT INTO image (mid, cid, about, price, item, name1, name2, name3, name4) ".
"VALUES ('','$cat','$about','$price','$item','$name1','$name2','$name3','$name4')";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); }


?>

如果我正确理解您的问题,您需要更改:

$fileinsert[]=$filePath;
$name1=basename($_FILES['image01'][$fileName]);//the file name of the first actual jpg
$name2=basename($_FILES['image02'][$fileName]);//the file name of the sencond actual jpg
$name3=basename($_FILES['image03'][$fileName]);//the file name of the third actual jpg
$name4=basename($_FILES['image04'][$fileName]);//the file name of the fourth actual jpg
致:

然后你需要改变:

$fileinsert[]=$filePath;
$name1=basename($_FILES['image01'][$fileName]);//the file name of the first actual jpg
$name2=basename($_FILES['image02'][$fileName]);//the file name of the sencond actual jpg
$name3=basename($_FILES['image03'][$fileName]);//the file name of the third actual jpg
$name4=basename($_FILES['image04'][$fileName]);//the file name of the fourth actual jpg
致:


像这样的事情应该可以做到。

我很乐意。是在点击星星吗?@userX不,是我答案左上角的复选标记,在投票分数下面。明白了,非常感谢你的帮助。在过去的两天里,我学到了很多,尽管现在我必须重新格式化我的查询以满足3nf的要求!