Php check if file exists

can anyone advise me how to do a check to determine if the file exists in the database or not before we upload it?

I want to upload a file to the database, but before it saves, I want to check that the file already exists first. if so, do not perform the insert.

I used this link for uplaoding files.

Thank you very much.

+3
source share
2 answers

I'm not sure if this is what you are asking for, but have you used the PHP built-in function, file_exists (ABSOLUTE-PATH-TO-FILE)?

$exists = file_exists('myfile.doc');
if(!$exists) {
// do your processing
}

http://php.net/manual/en/function.file-exists.php

, , , :

SELECT * FROM my-table WHERE my-column = 'my-uploaded-file-name';
+18

, , " ", :

$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

, , , , , , , , .

, , :

select *
from upload
where name = '$fileName'
    and size = '$fileSize'
    and type = '$fileType'
    and content = '$content'

, , , " ".


BTW: , , , - (. md5 / sha1).


BTW 2: SQL Injections, , , : , / " ", , :

$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";
+2

Source: https://habr.com/ru/post/1724422/


All Articles