-1

イメージ ファイル自体ではなく、イメージ パスをデータベースに挿入するという特定のアドバイスを受け取りました。しかし、私はまだ問題があり、まったく機能しません。私のコードがこのようなものである場合、SQL テーブルをどのように設定すればよいでしょうか? そして私の間違いも指摘してください。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php

session_start();

$dbhost = 'localhost';
$dbuser = 'root';
$dbpassword = '';

$dbconnect = mysql_connect($dbhost, $dbuser, $dbpassword) or die("gg");
$dbselect = mysql_select_db('uploadimg', $dbconnect) or die("gg1");

mysql_close($dbconnect);

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Image Path Into SQL Database</title>
</head>

<body>

<?php

//getting the filename of the image file.
$filename = $_FILES["image"]["name"];

//directory name to be stored.
$path = "C:/xampp/htdocs/Test/images";

//uploading the image file with the image file name into the directory.
    if(move_uploaded_file($_FILES["image"]["tmp_name"],$path."/".$filename)) {

//if the image is stored success into the directory then we are going to store into database.

//the real path with the filename.

        $mysql_path = $path."/".$filename;

//sql query to be executed.
        $sql = "INSERT INTO uploadimg(filename,path) VALUES ('$filename','$mysql_path')";

//executing the query.
        if(mysql_query($sql)) {

            echo 'path inserted into database';

        }

        else {

            echo 'path not inserted into database';

        }

    }

    else {

        echo 'file not uploaded';

    }
}

?>

<form method="POST" enctype="multipart/form-data">
      File:
      <input type="file" name="image"> <input type="submit" value="Upload" />
</form>


</body>
</html>
4

1 に答える 1