简体   繁体   中英

uploading images in database mysql using php

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>

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'];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM