Eğer bağlantılı makaleden bakılırsa, bir dosya bu sorgu idam edildiğinde "veritabanına yüklenen" olarak kabul edilir:
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
Bir dosya "veritabanına yüklendi" olmadığını kontrol etmek için bir yol anlamına gelir bir dosya yükledi edilirken aynı adı, dosya türü ve içeriği ile DB zaten bir giriş varsa, kontrol etmek olacağını Geçerli bir.
Ben böyle bir giriş bu gibi bir sorgu kullanarak zorlama olabilir varsayalım:
select *
from upload
where name = '$fileName'
and size = '$fileSize'
and type = '$fileType'
and content = '$content'
Bu sorgu bir sonuç döndürürse, dosya büyük olasılıkla zaten "veritabanında" dir.
BTW : To avoid checking the content of the whole file, a solution might be to add a new column to your upload table, to store some kind of hash of the file (see md5
and/or sha1
for instance).
BTW 2 : you should read a bit about SQL Injections, before using the code presented in this article without really understanding it : the following portion of code, copy/pasted from the "code for downloading files" section, is quite frightening, for instance :
$id = $_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";