푸르생 스토리

mysql에 이미지 저장 하고 경로 불러오기 본문

카테고리 없음

mysql에 이미지 저장 하고 경로 불러오기

푸르생 2021. 10. 14. 17:10
728x90
반응형
SMALL

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>imageUpload</title>
</head>
<body>
    <form action="imgUplodP.php" method="post" onsubmit="return sendit()">
    <h2>imageUpload</h2>
    <div class="content">
        <div class="nav">
            <ul>
                <li>파일 업로드 : </li>
            </ul>
        </div>
        <div class="nav_info">
            <input type="file" name="imageUpload" id="imageUpload">    
        </div>
        <p><button type='submit' id="reg_btn">저장</button></p>
    </div>
    </form>
</body>
</html>

PHP

<?php

if(isset($_POST['submit'])) {

    //Process the image that is uploaded by the user

    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
    $uploadOk = 1;
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

    if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["imageUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }

    $image=basename( $_FILES["imageUpload"]["name"],".jpg"); // used to store the filename in a variable

    //storind the data in your database
    $query= "INSERT INTO items VALUES ('$id','$title','$description','$price','$value','$contact','$image')";
    mysql_query($query);

    require('heading.php');
    echo "Your add has been submited, you will be redirected to your account page in 3 seconds....";
    header( "Refresh:3; url=account.php", true, 303);
}

while($row = mysql_fetch_row($result)) {
    echo "<tr>";
    echo "<td><img src='uploads/$row[6].jpg' height='150px' width='300px'></td>";
    echo "</tr>\n";
}

?>
728x90
반응형
LIST