Basit PHP yükleme formu değil çalışma

3 Cevap

Ben dizinlerine yazma ile uğraşırken çok sorunları çalıştırmak gibi görünüyor. Birisi bu komut dosyası üzerinden bakmak, ve çalışmıyor yüzden lütfen bana olsaydı, çok minnettar olurum.

Formdan dosyayı yüklemeden sonra, ben bu çıkışı herhangi bir hata yok .. bir şey alamadım, sadece sadece yeniler.

Teşekkürler, Lea

<?php include ('config.php');
 if( isset($_POST['submit']) ) {

$target = ''.$_SERVER['DOCUMENT_ROOT'].'/images/';
$target = $target . basename( $_FILES['photo']['name']) ;
$url = basename( $_FILES['photo']['name']) ;

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
$moved =  "File has been moved to location $target";

$name = mysql_real_escape_string($_POST['photoname']);
mysql_query("INSERT INTO photos (photo_name, photo_image) VALUES ('$name',  '$url' )") or die(mysql_error());
$success = "Photo has been added!";

  } else {

$moved = "File has not been moved to $target";
$success = "Failed to upload:(";

  }

} ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Photo Upload</title>
<meta name="robots" content="index, follow" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="<?php echo $globalurl; ?>styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="holder">
<br /><br />
<b>Add a new photo</b>
<hr />
<br />
<b><?php echo "$success<br />"; ?>
<?php echo "$moved<br />"; ?></b>
  <form enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF; ?>">
    <table cellspacing="0" cellpadding="0" width="500px">
      <tbody>
        <tr>
          <td valign="top">Photo Name:</td>
          <td valign="top">
            <input type="text" name="photoname" /><br />
            <br />
            </td>
        </tr>
        <tr>
          <td valign="top">Photo:</td>
          <td valign="top">
  <input type="file" name="photo"><br />
            <br />
            </td>
        </tr>
      </tbody>
    </table>
    <input type="submit" value="submit" />
  </form>
</div>
</body>
</html>

3 Cevap

Hatalar için PHP kodu kontrol etmeden, sıyrılıyor ilk şey şudur:

isset($_POST['submit'])

her zaman false döndürür. Input type = name niteliği gönderilmek üzere "teslim" olmalı "submit":

<input type="submit" value="submit" name="submit" />

İşte hata bu böyle düğmeye kullanımını teslim olduğunu:

<input type="submit" value="submit" name="submit" />

Tamam bitti

<?php 
if( isset($_POST['submit']) ) {
 $target = 'images/';
 echo $target = $target . basename( $_FILES['photo']['name']) ;

 if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
  $moved =  "File has been moved to location $target"; 
  $success = "Photo has been added!";
 } 
 else { 
 $moved = "File has not been moved to $target";
 $success = "Failed to upload:(";
  }
} 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Photo Upload</title>
<meta name="robots" content="index, follow" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="<?php echo $globalurl; ?>styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="holder">
<b>Add a new photo</b>
<?php echo "$success<br />"; ?>
<?php echo "$moved<br />"; ?>
  <form enctype="multipart/form-data" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
    <table cellspacing="0" cellpadding="0" width="500px">
      <tbody>
        <tr>
          <td valign="top">Photo Name:</td>
          <td valign="top">
            <input type="text" name="photoname" /><br />
            <br />
            </td>
        </tr>
        <tr>
          <td valign="top">Photo:</td>
          <td valign="top">
    <input type="file" name="photo">
            </td>
        </tr>
      </tbody>
    </table>
    <input type="submit" value="submit" id="submit" name="submit" />
  </form>
</div>
</body>
</html>