0
BLOB型が常に空で、他のメソッドではフォルダに画像を挿入できないため、値を挿入するのが難しいです。あなたは道を示すことができます。ありがとう!このコードは、画像をフォルダに保存して表示する名前でアクセスしますが、画像をフォルダに保存することはありません。私は編集して、ここにJavaScriptとCSSを含むフォームを含めます。それはどのように乱雑ですが、私は初心者です。ありがとう。BLOBのファイルをデータベースにアップロードできません。PHPのディレクトリの問題
<?php
include("../views/post_form.php");
require("../includes/include.php");
require("../includes/sess_n.php");
if ($_SERVER["REQUEST_METHOD"]== "POST")
{
$usertext = $_POST["usertext"];
$image = $_FILES['image']['name'];
$talent =$_POST["talenttype"];
if(empty($usertext) || empty($image)|| empty($talent))
{
die();
}
$id = $_SESSION["id"];
$folder ="images/".basename($_FILES['image']['name']);
move_uploaded_file($_FILES['image']['tmp_name'],$folder) ;
$query = mysqli_query($link,"SELECT * FROM `upload` WHERE id = '$id'");
$upload = mysqli_query($link,"INSERT INTO `upload` (description,image,talent,folder) VALUES('$usertext','$image','$talent','$folder ')");
}
?>
表示するには、写真を保存しないでフォルダに保存します。私はデータベースに挿入されていないBLOBメソッドを使用しました。
<?php
include("../views/feeds_form.php");
require("../includes/include.php");
require("../includes/sess_n.php");
$query = mysqli_query($link,"SELECT * FROM `upload` ");
if ($query === false)
{
die();
}
echo '<table>';
while ($run = mysqli_fetch_assoc($query))
{
echo '<tr>';
echo '<td>';?> <img src =" <?php echo $run["image"]; ?>" height=100 width=100> <?php echo '<td>';
echo '<td>'; echo $run["description"]; echo '<td>'; echo $run["folder"];echo '<td>';
echo '</tr>';
}
echo '</table>';
?>
ここのフォーム。
<?php
include("../public/header.php");
?>
<div><title>post</title></div>
<style>
.form-inline
{
text-align: center;
margin-bottom: 50px;
}
</style>
<script type="text/javascript">
function validate(){
var usertext = document.getElementById("usertext");
var talent = document.getElementById("talenttype");
var image = document.getElementById("image");
if (usertext.value === "" && talent.value === "" && image.value ==="")
{
alert("Field Must Not be Empty");
}
}
</script>
<form class="form-inline" method ="POST" action ="post.php" enctype="multipart/form-data" onsubmit= "return validate();">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail3"> </label>
<textarea class="form-control" id = "usertext" name ="usertext" rows="5" placeholder="Describe Person Here"></textarea> <br><hr>
<label class="sr-only" for="exampleInputEmail3"></label><br>
<div class="form-group">
<label for="exampleInputPassword1"></label>
<input type="file" class="form-control" id = "image" id="exampleInputPassword1" name="image" placeholder="image">
</div> <br><br><br> <hr>
<div class="form-group">
<label for="exampleInputPassword1"></label>
<input type="text" class="form-control" id = "talenttype" id="exampleInputPassword1" name = "talenttype" placeholder="Talent-Type"><br><br>
</div> <hr>
<div>
<button type="submit" name ="post" class="btn btn-default">Post</button><br>
</div>
</div>
</form>
<?php
include("../public/footer.php");
?>
ブロブを使用すると、通常のファイルに格納するのと非常によく似た結果が得られます。一般的なWebサーバーは静的ファイルを処理するのに優れているため、多くのパフォーマンスが低下します。私はファイルを使うことに焦点を当てる。実際にあなたの問題は何ですか?どのようなエラーが発生しますか? –
データベースに保存するコードを表示 – RiggsFolly
[よくある質問と回答](http://stackoverflow.com/help/on-topic) ://stackoverflow.com/help/how-to-ask) [完璧な質問](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) そして、 [最小限の、完全で検証可能な例](http://stackoverflow.com/help/mcve)を作成する方法 – RiggsFolly