Reputation: 23
i am building a script using php to upload images in database but i am stuck due to the error under: when i open my page in browser following message shows to me:
Notice: Undefined index: image in C:\xampp\htdocs\12\index.php on line 10 please select a file
under is my script in initial form :
<html>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
File:<input type="file" name="image" /><input type="submit" value="upload" />
</form>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("databaseimage") or die(mysql_error());
//files properties
echo $file = $_FILES["image"]["tmp_name"];
if(!isset($file))
echo'please select a file';
else{
$image = $_FILES['image']['tmp_name'];
}
?>
</body>
</html>
Upvotes: 1
Views: 420
Reputation: 5351
Check, if there is an upload first (and therefore, $_FILES["image"]
is existing at all):
if (isset($_FILES["image"]))
{
$file = $_FILES["image"]["tmp_name"];
if (!isset($file)) {
echo 'please select a file';
} else {
$image = $_FILES['image']['tmp_name'];
}
}
Upvotes: 2