본문 바로가기
Coding/PHP

[PHP] 특정 디렉터리에서 가장 최신 파일 출력 및 SQL ISNERT

by jamong1014 2022. 11. 30.
반응형
<?php
    include "db.php";

    $files = scandir('data', SCANDIR_SORT_DESCENDING);
    $newest_file = $files[0];
    $dir = 'C:/xampp/htdocs/ttest/data/';

    $query = "insert into studytest (image) values (load_file('$dir$newest_file'))";
     
    if(mysqli_query($dbh, $query))
    {
        echo '<script type="text/javascript"> alert("image profile uploaded"); </script>';
    }else
    {
        echo '<script type="text/javascript"> alert("image profile failed"); </script>';
    }


?>

 $files = scandir('data', SCANDIR_SORT_DESCENDING);
 $newest_file = $files[0];

* 해당 디렉터리에 있는 모든 파일을 내림차순으로 나열한 후 가장 큰 타임스탬프 값을 가져옴

 

웹 호스팅 서버를 이용하는 경우 서버 한대에서 여러 도메인에 사용 공간을 할당해 주는 방식이라 시스템 전체의 절대 경로 디렉터리를 못가져옴(load_file 방식이 아닌 file_get_contents으로 매개변수를 할당하여 사용해야 할 듯)

 

 

반응형

댓글