PHP / MySQL上传带有注释的图像并打印出来


PHP/MySQL upload image with comment and print it

我正在做一个网站,非常简单,顺便说一句,它已经完成了,但是有些问题让我解决了! 以下是 3 页:

索引.php http://pastebin.com/whQfhPEy
管理员.php http://pastebin.com/pQCsphCa
上传.php:

<?php
mysql_connect("localhost", "xxxx", "xxxx");
mysql_select_db("xxxx");
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>

索引.php打印通过管理员上传的消息/图像.php
admin.php用于提交数据/图像,以便可以在索引上显示这种方式.php
上传.php在管理员上按下提交按钮时调用.php

问题:我需要修改上传.php以某种方式在每个上传的图像上放置一个 ID,以便可以使用其 ID 打印在索引上.php它应该如何?

问题1:主要问题是在admin上.php填写表格并单击"提交"后,它不会将数据插入我的数据库表中,我缺少什么?

您发送了错误的 SQL。查纳奇valuevalues

改变

mysql_query("INSERT INTO BlogData ('title', 'category', 'content') VALUE('$title', '$category', '$content')");

mysql_query("INSERT INTO BlogData (`title`, `category`, `content`) VALUES('$title', '$category', '$content')");

问题2:我想在表格上添加"图片上传"选项,我该怎么做?http://www.w3schools.com/php/php_file_upload.asp

问题3:在索引上.php所有条目都被"打印",我如何显示我与表单一起上传的图像?

从数据库中获取图像路径并为其添加<img/>

此外,mysql_函数也已弃用。请改用mysqli_