PHP:上传图片后,它不会加载,而且存在漏洞

时间:2017-08-21 13:22:24

标签: php html mysql

<!DOCTYPE html>
<html>
<head>
<title>Filmovi</title>
</head>
<body>

    <form action="unos.php" method="POST" enctype="multipart/form-data">
    <table border = "1">
    <tr>
    <td>Naslov:</td>
    <td><input type="text" name="naslov" value="" /></td>
    </tr>
    <tr>
    <td>Žanr:</td>
    <td>
    <?php

    $conn = new mysqli('localhost', 'root', '', 'kolekcija');
    $result = $conn->query("SELECT id, naziv FROM zanr");

    echo "<select name = 'id'>";
    while($row = $result->fetch_assoc())
    {
        unset($id, $name);
        $id = $row['id'];
        $name = $row['naziv'];
        echo '<option value = "' . $id . '">'.$name.'</option>';
    }

    echo "</select>";

    ?>
    </td>
    </tr>
    <tr>
    <td>Godina:</td>
    <td>
    <select name = "godina">
    <?php

    for($i = 1900; $i <= 2020; $i++)
    {
        echo "<option value = " .$i . ">" .$i . "</option>";
    }

    ?>
    <option name = "godina"></option>
    </select>
    </td>
    </tr>
    <tr>
    <td>Trajanje:</td>
    <td><input type="integer" name="trajanje" value="" /></td>
    </tr>
    <tr>
    <td>Slika:</td>
    <td><input type="file" name="image" />
    <input type = "hidden" name = "size" value = "1000000000" /></td>
    </tr>
    <tr>
    <td>Gumb:</td>
    <td><input type="submit" name="submit" value="Unos" /></td>
    </tr>

        </table>
    </form>

</body>
</html>

<?php

$link = mysqli_connect("localhost", "root", "") or die 
(mysqli_connect_errno());
mysqli_select_db($link, "kolekcija") or die ("Nemoguće se spojiti na 
bazu!".mysqli_connect_errno());

if(isset($_POST['submit']))
{
    $filename = $_FILES["image"]["name"];
    $filepath = "/unos.php:116".$filename;
    $naslov=$_POST['naslov'];
    $trajanje = $_POST['trajanje'];
    $zanr = $_POST['id'];
    $godina = $_POST['godina'];
    move_uploaded_file($filename, $filepath);

        $sql = "INSERT INTO filmovi (id, naziv_filma, trajanje, slika, 
id_zanr, godina)
                VALUES('null', '{$naslov}', '{$trajanje}' ,'{$filepath}', 
'{$zanr}', '{$godina}');";
     $result = mysqli_query($link, $sql) or die("Error in Query insert: " . 
mysqli_connect_errno());

    }

$msg = "";

$sql = "SELECT id, slika, naziv_filma, godina, trajanje FROM filmovi";
$myData = mysqli_query($link, $sql); 
echo "<table border = '1'>
<tr>
<th>Slika</th><th>Naziv filma</th><th>Godina</th><th>Trajanje</th>
<th>Akcija</th></tr>";
while($record = mysqli_fetch_array($myData)) 
    {
    echo "<form action = 'unos.php' method = 'post' enctype='multipart/form-
data'>";
    echo "<tr>";
    echo "<td>" . $msg.= '<img 
src="data:image/jpeg;base64,'.base64_encode($record['slika']) .'"/>' . "
</td>";
    echo "<td>" . $record['naziv_filma'] . "</td>";
    echo "<td>" . $record['godina'] . "</td>";
    echo "<td>" . $record['trajanje'] . "</td>";
    echo '<td>[<a href="unos.php?film='.$record[0].'">obriši</a>]</td>';

    if(isset($_GET['film']))
    {
        $id = ($_GET['film']);

        $sql_delete = "DELETE FROM filmovi WHERE id = {$id}";

        mysqli_query($link, $sql_delete);

        break;
    }


    echo "</tr>";
    echo "</form>";
    }




echo "</table>";

?>

好的,这是我的代码,我有一个编程课程,这就是 分配新建分配FY。我们的想法是制作一个表单,您可以在其中放置有关电影,名称,流派,制作年份和上传图片的信息。 Everythign工作并且已经完成,但唯一的问题是上传图片后(直接在mysql数据库中,我没有代码将图片存储在本地磁盘上),它赢了&#39 ; t在浏览器中加载,刷新浏览器后,图片再次上传。似乎我有一个循环somwhere但我无法弄清楚导致我一直在做什么,并推迟了几个月的代码,因为我被卡住了。有人可以帮帮忙吗?非常感谢你提前帮助!

0 个答案:

没有答案