Yüklenen dosya ve dize dosya karşılaştırmak nasıl

1 Cevap php

Ben xammp sunucu görüntü dosyalarını yüklemek için bu kodu kullanabilirsiniz:

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 100000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file, File must be less than 100Kb in size with .jpg, .jpeg, or .gif file extension";
  }
?>

What do I do to compare the file name of the uploaded files with the text inputted by the user? My goal is to be able to compare the user input(ID number) and the file name of the image file which should also be an ID number. So that I will be able to display the image that corresponds with the ID Number provided. What do I need to do?Please give me an idea on how can I achieve this. Thanks

1 Cevap

Eğer kullanıcı yüklenen dosyaya girdiği kimlik numarasını karşılaştırmak isteyen var, pek mantıklı değil mi?

$idnumber = $_POST['id']; //User inputted

if($_FILES["file"]["name"]) != "$idnumber" {
  exit("Does not match");
}

Yoksa onların görüntü kimliği yanında her görüntü yolu için bir veritabanı girişi oluşturmanız gerekir tr-kitle dosyaları maç isteyen konum.

Eğer kimlik numarası görüntüsünü görüntülemek isteyen iseniz:

$idnumber = $_POST['id']; //User inputted

print "<img src='/images/$idnumber.ext'/>";