Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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_Pdo - Fatal编程技术网

上载php上载页面上的类别

上载php上载页面上的类别,php,mysql,pdo,Php,Mysql,Pdo,你好,我正在做一个有上传页面的项目,它在后台以dir/uploads/上传图片,并将其保存到用户_images表中我数据库中的url 所以,我想有一个分类画廊,但当他们上传时,我需要一个下拉菜单,让他们选择汽车、房子等 在我的图库中,我需要显示类别。我在想所有有id的类别 当我提交时,表格将是id和image_链接,在gallery页面中,我在这个div中指定我想要id=x的图像 有人能帮我吗?我会非常高兴的!ps:对不起,我的英语不好 编辑:我需要它与pdo再次感谢 upload.php

你好,我正在做一个有上传页面的项目,它在后台以dir/uploads/上传图片,并将其保存到用户_images表中我数据库中的url

所以,我想有一个分类画廊,但当他们上传时,我需要一个下拉菜单,让他们选择汽车、房子等

在我的图库中,我需要显示类别。我在想所有有id的类别

当我提交时,表格将是id和image_链接,在gallery页面中,我在这个div中指定我想要id=x的图像

有人能帮我吗?我会非常高兴的!ps:对不起,我的英语不好

编辑:我需要它与pdo再次感谢

upload.php

    <center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
            Select image to upload:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input type="submit" value="Upload Image" name="submit">
        </form></center>
</div>
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
    header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>

<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "<br>";
        echo "<br>";
        echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
        $uploadOk = 1;
    } else {
        echo "<br>";
        echo "<h1><center>File is not an image.</center></h1>";
        $uploadOk = 0;
    }
}

if (file_exists($target_file)) {
    echo "<br>";
    echo "<h1><center>Sorry, file already exists.</center></h1>";
    echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "<br>";
    echo "<h1><center>Sorry, your file is too large.</center></h1>";
    echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
    $uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
    echo "<br>";
    echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
    $uploadOk = 0;
}
if ($uploadOk == 0) {
    echo "<br>";
    echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";


} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
        echo " <meta http-equiv=\"refresh\" content=\"5;url=gallery-edit.php\" />";
        echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
        echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
        $sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
        $stmt = $db->prepare($sql);

        $stmt->bindValue(':image_link', $target_file3);

        $result = $stmt->execute();
    } else {
        echo "<br>";
        echo "<center>Sorry, there was an error uploading your file.</center>";
        echo " <center><a href = gallery-edit.php>Go back </a></center>";
    }
}
?>
galleryupload.php

    <center><form action="galleryupload.php" method="post" enctype="multipart/form-data">
            Select image to upload:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input type="submit" value="Upload Image" name="submit">
        </form></center>
</div>
<?php
session_start();
if(isset($_SESSION['sess_user_id']) && $_SESSION['sess_user_id'] != "") {
} else {
    header('location:index.php');
}
?>
<body style="background-color: lightgray"></body>
<center><img src="../images/x.png"></center>

<?php
include "db.php";
$target_file2 = "random-dir/";
$target_dir = "random-dir/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$target_file3 = $target_file2 .$target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "<br>";
        echo "<br>";
        echo "<h1><center>File is an image - " . $check["mime"] . "." ."</center></h1>";
        $uploadOk = 1;
    } else {
        echo "<br>";
        echo "<h1><center>File is not an image.</center></h1>";
        $uploadOk = 0;
    }
}

if (file_exists($target_file)) {
    echo "<br>";
    echo "<h1><center>Sorry, file already exists.</center></h1>";
    echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "<br>";
    echo "<h1><center>Sorry, your file is too large.</center></h1>";
    echo "<h1><a href = gallery-edit.php>Go back </a></h1>";
    $uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
    && $imageFileType != "gif" ) {
    echo "<br>";
    echo "<h1><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.</center></h1>";
    $uploadOk = 0;
}
if ($uploadOk == 0) {
    echo "<br>";
    echo "<h1><center>Sorry, your file was not uploaded.</center></h1>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<h1><center><a href = gallery-edit.php>Go back </a></center></h1>";


} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "<h1><center>The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.</center></h1>";
        echo " <meta http-equiv=\"refresh\" content=\"5;url=gallery-edit.php\" />";
        echo "<center><h1>You Will be redicted to user gallery in 5 seconds...</h1></center>";
        echo "<center><h1>If your browser doesn't support redict please<a href=gallery-edit.php> click here </h1></a></center>";
        $sql = "INSERT INTO user_image (image_link) VALUES (:image_link)";
        $stmt = $db->prepare($sql);

        $stmt->bindValue(':image_link', $target_file3);

        $result = $stmt->execute();
    } else {
        echo "<br>";
        echo "<center>Sorry, there was an error uploading your file.</center>";
        echo " <center><a href = gallery-edit.php>Go back </a></center>";
    }
}
?>

什么东西没有按预期工作?你需要什么帮助?我会在“user\u image”表中为类别id添加一个类似“category\u id”的列,并将所选类别保存在其中。然后,您可以按类别加载所有图像,从用户图像中选择图像链接,其中类别id=123,其中123是要显示的类别的id。这就是你要找的吗?