PDA

View Full Version : مشکل با Undefined index:



milad_d993
شنبه 05 فروردین 1396, 15:28 عصر
سلام.
دوستان من این کد رو برای آپلود عکس نوشتم. تو سمت سرور خطای زیر رو میده:اشتباه: مشکل از کجاست؟؟؟



Notice: Undefined index: image in C:\xampp\htdocs\dashboard\...\gallery-op.php on line 1




<form method="post" action="gallery-op.php">
<table>
<tr><td><input type="file" name="image" accept="image/*"></td></tr>
<tr><td><input type="submit" value="درج تصویر"></td></tr>
</table>
</form>




if(is_uploaded_file($_FILES["image"]["tmp_name"])){

$target_dir = "gallery/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$pictureFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSIO N));
$uploadOk = 1;

// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check === false)
$uploadOk = 0;

// Check file size
if ($_FILES["image"]["size"] > 500000)
$uploadOk = 0;

// Allow certain file formats
if($pictureFileType != "png" && $pictureFileType != "gif" && $pictureFileType != "bmp" && $pictureFileType != "jpg" && $pictureFileType != "jpeg")
$uploadOk = 0;

// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 1){

$image = $target_dir.$row["id"].'.'.$pictureFileType;
move_uploaded_file($_FILES["image"]["tmp_name"], "../".$image);


mysql_query("insert into gallery values(null,'$image'",$con);
header("location:gallery.php?msg=insert");

}
}

plague
شنبه 05 فروردین 1396, 20:08 عصر
تو فرم باید enctype="multipart/form-data" بزاری