如何禁用文件上传(PHP)中的其他文件类型?

时间:2019-05-05 01:12:26

标签: php html sql

在有人提醒我之前,我想告诉我我看到了类似的话题,但由于我不太擅长PHP而无法解决我的问题,我需要特别的PHP代码帮助,基本上它接受来自上传的所有文件扩展名,但不是安全..我只想允许图像类型,如果这样做不那么容易,那么您可以尝试修复我的PHP代码,即使禁用.php文件也将真正有用且安全。预先感谢

<? $sayfa="gorseller"; include("_inc_head.php");?>





<table width="1020" border="0" align="center" cellpadding="0" cellspacing="0">




  <? include("_inc_ust.php");?>



  <tr>
    <td valign="top" bgcolor="#FFFFFF"  >


    <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td> <h1>Bannerlar</h1></td>
            <td> <a href="?islem=ekle"> Yeni ekle</a></td>
            <td width="20%"><form name="form" id="form">
              <select name="jumpMenu" id="jumpMenu" onChange="MM_jumpMenu('parent',this,0)">
              <option value="admin_banner.php">cL Listele</option>
                 <option value="?islem=listele&grupID=0&hangisitede=1">Anasayfa</option>
                   <option value="?islem=listele&grupID=96&hangisitede=1">Tüm sayfalar</option>
                     <option value="?islem=listele&grupID=99&hangisitede=1">Tur detay sayfası</option>
                      <option value="?islem=listele&grupID=98&hangisitede=1">Sık sorulan sorular</option>
                      <option value="?islem=listele&grupID=97&hangisitede=1">Ödeme sonuç sayfası</option>
                      <option value="">-----------------------</option>


             <? $sql_bul_kat = "SELECT * FROM $table_grup  ORDER BY grup ASC" ;

    $sql_result_bul_kat=mysql_query($sql_bul_kat,$connection) or die ("kategoriyi bulamadık");

 while ($row=mysql_fetch_array($sql_result_bul_kat)) {

    $gidd = $row["gid"];
    $grupp = $row["grup"];?>

    <option value="?islem=listele&grupID=<?=$gidd?>&hangisitede=1"><?=$grupp?></option>
    <?

} mysql_free_result($sql_result_bul_kat);?> 




              </select>
            </form></td>
            <td width="20%"><form name="form" id="form">
              <select name="jumpMenu" id="jumpMenu" onChange="MM_jumpMenu('parent',this,0)">
              <option value="admin_banner.php">BUTİK TURLAR Listele</option>
                 <option value="?islem=listele&grupID=0&hangisitede=2">Anasayfa</option>
                   <option value="?islem=listele&grupID=96&hangisitede=2">Tüm sayfalar</option>
                     <option value="?islem=listele&grupID=99&hangisitede=2">Tur detay sayfası</option>
                      <option value="?islem=listele&grupID=98&hangisitede=2">Sık sorulan sorular</option>
                      <option value="?islem=listele&grupID=97&hangisitede=2">Ödeme sonuç sayfası</option>
                      <option value="">-----------------------</option>


             <? $sql_bul_kat = "SELECT * FROM $table_grup  ORDER BY grup ASC" ;

    $sql_result_bul_kat=mysql_query($sql_bul_kat,$connection) or die ("kategoriyi bulamadık");

 while ($row=mysql_fetch_array($sql_result_bul_kat)) {

    $gidd = $row["gid"];
    $grupp = $row["grup"];?>

    <option value="?islem=listele&grupID=<?=$gidd?>&hangisitede=2"><?=$grupp?></option>
    <?

} mysql_free_result($sql_result_bul_kat);?> 




              </select>
            </form></td>
            <td width="20%"><form name="form" id="form">
              <select name="jumpMenu" id="jumpMenu" onChange="MM_jumpMenu('parent',this,0)">
              <option value="admin_banner.php">cL Listele</option>
                 <option value="?islem=listele&grupID=0&hangisitede=3">Anasayfa</option>
                   <option value="?islem=listele&grupID=96&hangisitede=3">Tüm sayfalar</option>
                     <option value="?islem=listele&grupID=99&hangisitede=3">Tur detay sayfası</option>
                      <option value="?islem=listele&grupID=98&hangisitede=3">Sık sorulan sorular</option>
                      <option value="?islem=listele&grupID=97&hangisitede=3">Ödeme sonuç sayfası</option>
                      <option value="">-----------------------</option>


             <? $sql_bul_kat = "SELECT * FROM $table_grup  ORDER BY grup ASC" ;

    $sql_result_bul_kat=mysql_query($sql_bul_kat,$connection) or die ("kategoriyi bulamadık");

 while ($row=mysql_fetch_array($sql_result_bul_kat)) {

    $gidd = $row["gid"];
    $grupp = $row["grup"];?>

    <option value="?islem=listele&grupID=<?=$gidd?>&hangisitede=3"><?=$grupp?></option>
    <?

} mysql_free_result($sql_result_bul_kat);?> 




              </select>
            </form></td>
          </tr>
        </table> 
      <br /><br />
     <? if($_POST['islem']=="guncelle"){

         $file_name = $_FILES['file']['name'];

        if($file_name<>""){


$target = $define_real_path."anasayfa/".basename($_FILES['file']['name']) ;


            if(move_uploaded_file($_FILES['file']['tmp_name'],$target)){

                 $tarih=strtotime("now");

                 mysql_query("UPDATE store_gorsel SET tarih='$tarih', dosya = '$file_name'  WHERE kayitID = '$_POST[kayitID]'");

if(mysql_error()){ 

    echo"Görsel üncellenemedi! Tekrar deneyiniz.<br />"; 

} else { 

    echo"Görsel güncellendi.<br />";
} 

            } else { 

                $endresult = "<font size=\"2\">Dosya yüklenemiyor!</font>"; 

            }






     }



$eski = array("'");
 $yeni   = array("\'");

// $aciklamaNedir = str_replace($eski, $yeni, $_POST['aciklamaNedir']);
 $aciklamaNedir =$_POST['aciklamaNedir'];

         mysql_query("UPDATE store_gorsel SET hangisite = '".$_POST['siteID']."', urunID = '$_POST[urunID]', grupID = '$_POST[grupID]', koleksiyonID =
'$_POST[koleksiyonID]', kategoriID = '$_POST[kategoriID]',altkategoriID = '$_POST[altkategoriID]',markaID = '$_POST[markaID]', sira = '$_POST[sira]', aciklama =
'$aciklamaNedir', link = '$_POST[link]', bolum = '$_POST[bolum]', yayinda = '$_POST[durum]'  WHERE kayitID = '$_POST[kayitID]'");

if(mysql_error()){ 

    echo"Güncellenemedi! Tekrar deneyiniz."; 

} else { 

    echo"Güncellendi";
} 


     }

      if($_GET['islem']=="sil" ){
  mysql_query( "DELETE FROM store_gorsel WHERE kayitID='$_GET[kayitID]'");

  if(mysql_error()){ 

    echo"silinemedi! Tekrar deneyiniz.<br />  <br />  "; 

} else { 

    echo"silindi.<br />  <br />  ";
}
  }


    if ($_GET['islem']=="ekle"){?>
<form name="form1" method="post" action="admin_banner.php" enctype="multipart/form-data">
  <table width="100%" border="0" cellspacing="1" cellpadding="1">


  <tr><TD colspan="2" align="left" style="border-bottom:1px solid #efefef; padding-bottom:10px" >
<? 
$ax=1;

$sql = "SELECT * FROM store_ayar " ;    
$sql_result=mysql_query($sql,$connection) or die ('verileri alamadik');    
while ($row=mysql_fetch_array($sql_result)) {    
$gid = $row["kayitID"];    
$grupadi = $row["sitesahibi"];


?>  

<input type="radio" name="siteID" id="siteID<?=$gid?>" value="<?=$gid?>" <? if($gid==1){ ?>checked="checked"<? }?> />
<label for="siteID<?=$gid?>"><?=$grupadi?></label> &nbsp;&nbsp;&nbsp;

 <? 

 $ax++;
 }    mysql_free_result($sql_result);    ?>

</td></tr>




 <tr>
      <td align="right">Grup : </td><td><select name="grupID" id="grupID">

     <option value="0" selected="selected">Anasayfa</option>
       <option value="96">Tüm sayfalar</option>
       <option value="98">Sık sorulan sorular</option>
        <option value="97">Ödeme sonuç sayfası</option>
       <option value="99">Tur detay sayfası</option>


    <? $sql_bul_kat = "SELECT * FROM $table_grup  ORDER BY grup ASC" ;

    $sql_result_bul_kat=mysql_query($sql_bul_kat,$connection) or die ("kategoriyi bulamadık");

 while ($row=mysql_fetch_array($sql_result_bul_kat)) {

    $gid = $row["gid"];
    $grup = $row["grup"];?>

    <option value="<?=$gid?>"><?=$grup?></option>
    <?

} mysql_free_result($sql_result_bul_kat);?>  
<option value="99">KATEGORİLER</option>
  </select>
        veya tur ID&nbsp;:&nbsp;
        <input name="urunID" type="text" class="Form1" id="urunID" size="6" /></td></tr>
    <tr> 
      <td width="99" class="yazi"> 
        <div align="right">Sıra&nbsp;:&nbsp;</div>      </td>
      <td width="751" height="35">          <input name="sira" type="text" class="Form1" id="sira" size="2">        </td>
    </tr>
     <tr> 
       <td width="99" class="yazi"> 
         <div align="right">Link&nbsp;:&nbsp;</div>      </td>
       <td width="751" height="35">          <input name="link" type="text" class="Form1" id="link" size="100">        </td>
     </tr>
     <tr>
      <TD height="22" align="right" class="yazi">A&ccedil;ıklama : </TD>
      <TD colspan="2"><label for="aciklamaNe"></label>
        <input name="aciklamaNedir" type="text" id="aciklamaNedir" value="" size="100" maxlength="250">      </TD>
      </TR>
    <tr>
      <TD align="right" class="yazi">G&ouml;rsel : </TD>
      <TD colspan="2">
        <INPUT NAME="file" TYPE="file" class="Form1" id="file"></TD>
      </TR><tr>
      <TD height="22" align="right" class="yazi">B&ouml;l&uuml;m : </TD>
      <TD colspan="2"><input name="bolum" type="radio" id="radio" value="1" checked="checked">
        <label for="bolum">1</label>
        &nbsp;   &nbsp;
<input type="radio" name="bolum" id="radio" value="2">
        <label for="bolum">2</label>
           &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="3">
        <label for="bolum">3</label>
          &nbsp;   &nbsp;
             <input type="radio" name="bolum" id="radio" value="4">
        <label for="bolum">4</label>
          &nbsp;   &nbsp;
             <input type="radio" name="bolum" id="radio" value="5">
        <label for="bolum">5</label>
          &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="6">
        <label for="bolum">Arka zemin</label>

        </TD>
      </TR><tr>
      <TD height="22" align="right" class="yazi">Yayınla : </TD>
      <TD colspan="2"><input name="durum" type="checkbox" id="durum" value="1" checked="checked">
        <label for="durum"></label></TD>
      </TR>
 <tr valign="bottom">
   <td height="30" colspan="2" class="yazi">
     <input type="hidden" name="islem" value="ekle1">
     <input type="submit" name="Submit2" value=" E K L E " class="BUTON">      </td>
 </tr>
  </table>

</form>

    <? } if ($_POST['islem']=="ekle1") {




  $file_name=$_FILES['file']['name'];

   $tarih=strtotime("now");


$eski = array("'");
 $yeni   = array("\'");

 $aciklamaNedir = str_replace($eski, $yeni, $_POST['aciklamaNedir']);


      mysql_query("INSERT INTO store_gorsel (tarih, dosya,link, yayinda, bolum, sira, aciklama, grupID, urunID, koleksiyonID, kategoriID, altkategoriID,
hangisite) VALUES
('$tarih','$file_name','$_POST[link]','$_POST[durum]','$_POST[bolum]','$_POST[sira]','$aciklamaNedir','$_POST[grupID]','$_POST[urunID]','$_POST[koleksiyonID]','
$_POST[kategoriID]','$_POST[altkategoriID]','".intval($_POST['siteID'])."')");

      echo mysql_error();


    $target = $define_real_path."anasayfa/".basename($_FILES['file']['name']) ;


            if(move_uploaded_file($_FILES['file']['tmp_name'],$target)){

                echo "Dosya yüklendi. "; 

            } else { 

                $endresult = "<font size=\"2\">Dosya yüklenemiyor!</font>"; 

            }







      echo "<span class=\"yazi\">eklendi.</span><br>";

 } ?>




      <? if($_GET['islem']=="detay"){

    $sql_bul_urun = "SELECT * FROM store_gorsel WHERE kayitID='$_GET[kayitID]' " ;

    $sql_result_bul_urun=mysql_query($sql_bul_urun,$connection) or die ("ürünü bulamadık");


    while ($row=mysql_fetch_array($sql_result_bul_urun)) {

     $dosya = $row["dosya"];
     $link = $row["link"];
     $bolum = $row["bolum"];
    $grupID = $row["grupID"];
    $kategoriID = $row["kategoriID"];
    $altkategoriID = $row["altkategoriID"];
    $koleksiyonID = $row["koleksiyonID"];
        $markaID = $row["markaID"];
$aciklamaNedir = $row["aciklama"];
    $sira = $row["sira"];
    $yayinda = $row["yayinda"];
     $kayitID = $row["kayitID"]; 
    $urunID = $row["urunID"]; 
    $tarih = $row["tarih"]; 
    $hangisitede= $row["hangisite"]; 

     if($dosya!=''){?>
<a href="<?=$link?>"><img src="/anasayfa/<?=$dosya?>" border="0" alt="" /></a> <br /><br /><? }?>
         <form name="form1" method="post" action="admin_banner.php" enctype="multipart/form-data">   

<? if($tarih>0){ 

 $tarih2=date('d.m.Y, H:i', $tarih);

 ?>
<?=$tarih2?>  tarihinde eklendi<br /><br />
<? }?>

 <table width="100%" border="0" cellspacing="1" cellpadding="1">
    <tr><TD colspan="2" align="left" style="border-bottom:1px solid #efefef; padding-bottom:10px" >
<? 
$ax=1;

$sql = "SELECT * FROM store_ayar " ;    
$sql_result=mysql_query($sql,$connection) or die ('verileri alamadik');    
while ($row=mysql_fetch_array($sql_result)) {    
$gid = $row["kayitID"];    
$grupadi = $row["sitesahibi"];



?>  

<input type="radio" name="siteID" id="siteID<?=$gid?>" value="<?=$gid?>" <? if($hangisitede==$gid){ ?>checked="checked"<? }?> />
<label for="siteID<?=$gid?>"><?=$grupadi?></label> &nbsp;&nbsp;&nbsp;

 <? 

 $ax++;
 }    mysql_free_result($sql_result);    ?>

</td></tr>






 <tr>
      <td align="right">Grup : </td><td> 
        <select name="grupID" id="grupID">


     <option value="0" <? if($grupID==0){ ?>selected<? }?>>Anasayfa</option>
     <option value="96" <? if($grupID==96){ ?>selected<? }?>>Tüm sayfalar</option>
       <option value="98" <? if($grupID==98){ ?>selected<? }?>>Sık sorulan sorular </option>
        <option value="97" <? if($grupID==97){ ?>selected<? }?>>Ödeme sonuç sayfası</option>
<option value="1" <? if($grupID==99){ ?>selected<? }?>>Tur detay sayfası</option>

    <? $sql_bul_kat = "SELECT * FROM $table_grup ORDER BY grup ASC" ;

    $sql_result_bul_kat=mysql_query($sql_bul_kat,$connection) or die ("kategoriyi bulamadık");

 while ($row=mysql_fetch_array($sql_result_bul_kat)) {

    $gid = $row["gid"];
    $grup = $row["grup"];?>

    <option value="<?=$gid?>" <? if($gid==$grupID){ ?>selected<? }?>><?=$grup?></option>>
    <?

} mysql_free_result($sql_result_bul_kat);?>  
  </select>
  veya &Uuml;r&uuml;n&nbsp;:&nbsp;
        <input name="urunID" type="text" class="Form1" id="urunID" size="6" value="<?=$urunID?>" /></td></tr>
    <tr> 
      <td width="99" class="yazi"> 
        <div align="right">Sıra&nbsp;:&nbsp;</div>      </td>
      <td width="751" height="35">          <input name="sira" type="text" class="Form1" id="sira" value="<?=$sira?>" size="2">        </td>
    </tr>
     <tr> 
       <td width="99" class="yazi"> 
         <div align="right">Link&nbsp;:&nbsp;</div>      </td>
       <td width="751" height="35">          <input name="link" type="text" class="Form1" id="link" value="<?=$link?>" size="100">        </td>
     </tr>
     <tr>
      <TD height="22" align="right" class="yazi">A&ccedil;ıklama : </TD>
      <TD colspan="2"><label for="aciklamaNe"></label>
        <input name="aciklamaNedir" type="text" id="aciklamaNedir" value="<?=$aciklamaNedir?>" size="100" maxlength="250">  </TD>
      </TR>
    <tr>
      <TD align="right" class="yazi">G&ouml;rsel : </TD>
      <TD colspan="2">
        <INPUT NAME="file" TYPE="file" class="Form1" id="file"></TD>
      </TR><tr>
      <TD height="22" align="right" class="yazi">B&ouml;l&uuml;m : </TD>
      <TD colspan="2"><input type="radio" name="bolum" id="radio" value="1" <? if($bolum==1){?>checked<? }?>>
        <label for="bolum">1</label>
        &nbsp;   &nbsp;
<input type="radio" name="bolum" id="radio" value="2"  <? if($bolum==2){?>checked<? }?>>
        <label for="bolum">2</label>
           &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="3"  <? if($bolum==3){?>checked<? }?>>
        <label for="bolum">3</label>

             &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="4"  <? if($bolum==4){?>checked<? }?>>
        <label for="bolum">4</label>
             &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="5"  <? if($bolum==5){?>checked<? }?>>
        <label for="bolum">5</label>
         &nbsp;   &nbsp;
         <input type="radio" name="bolum" id="radio" value="6"  <? if($bolum==6){?>checked<? }?>>
        <label for="bolum">Arka zemin</label>
        </TD>
      </TR><tr>
      <TD height="22" align="right" class="yazi">Yayınla : </TD>
      <TD colspan="2"><input name="durum" type="checkbox" id="durum" value="1"  <? if($yayinda==1){?>checked<? }?>>
        <label for="durum"></label></TD>
      </TR>
 <tr valign="bottom">
   <td height="30" colspan="2" class="yazi"><input type="hidden" name="kayitID" value="<?=$kayitID?>">
     <input type="hidden" name="islem" value="guncelle">
     <input type="submit" name="Submit2" value="g&uuml;ncelle" class="BUTON">      </td>
 </tr>
  </table> </FORM>

<? } mysql_free_result($sql_result_bul_urun);


      } if($_GET['islem']=="listele"){




if($_GET['durumu']==''){ $durumune=1; ?>

 Yayındakiler listelendi. <a href="?islem=listele&durumu=0&grupID=<?=$_GET['grupID']?>&hangisitede=<?=$_GET['hangisitede']?>">Yayın dışı olanları
listele</a>

 <? } else { $durumune = $_GET['durumu'];?>

 Yayın dışı olanlar listelendi. <a href="?islem=listele&durumu=1&grupID=<?=$_GET['grupID']?>&hangisitede=<?=$_GET['hangisitede']?>">Yayındakileri
listele</a> 
 <? }?>
 <br /><br />
 <?

    $sql_bul_urun = "SELECT * FROM store_gorsel WHERE hangisite='".intval($_GET['hangisitede'])."' AND yayinda='$durumune' AND grupID LIKE '$_GET[grupID]%'  ORDER
BY bolum ASC, sira ASC" ;

    $sql_result_bul_urun=mysql_query($sql_bul_urun,$connection) or die ("ürünü bulamadık");


    while ($row=mysql_fetch_array($sql_result_bul_urun)) {

      $kayitID = $row["kayitID"];
    $dosya = $row["dosya"];
      $link = $row["link"];
         $bolum = $row["bolum"];
        $aciklamaNedir = $row["aciklama"];
    ?>

<a href="?islem=detay&kayitID=<?=$kayitID?>"><? if($dosya!=''){?><img src="/anasayfa/<?=$dosya?>" border="0" alt="" /><? } else { echo $aciklamaNedir;}?></a><br
/> <a href="?islem=sil&kayitID=<?=$kayitID?>">sil</a><br /> <br /> 


<? } mysql_free_result($sql_result_bul_urun);?>      

<? }?>















    </td>
  </tr>

  </table>
 <? include("_inc_alt.php");?>

0 个答案:

没有答案