0

Hi im trying to upload an image to a database using php but every time i press the submit button i get the error

accept-file.php was not found

i dont see anywhere in my code where it will be directing to that is there something im missing?

    <?php
    session_start();
    $link = mysqli_connect("localhost","root","","pictureupload");
    if(isset($_POST['submit'])){
        $imagename=$_FILES["iamge"]["name"]; 
        $imagetmp=addslashes (file_get_contents($_FILES['image']['tmp_name']));
        $insert_image="INSERT INTO images VALUES('$imagetmp','$imagename')";
        mysqli_query($link,$insert_image);
    }
?>
<!DOCTYPE html>
<html>
<head>
    <Title>HomePage</Title>
    <link rel="stylesheet" type="text/css"  href="style.css">
</head>
<body>
<form action="accept-file.php" method="post" enctype="multipart/form-data">
    Your Image: <input type="file" name="image" size="25" />
    <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
GregHBushnell
  • 143
  • 12

2 Answers2

-1

change your form tag to

<form action="?"
Dimitri L.
  • 4,499
  • 1
  • 15
  • 19
-1

Your form has "accept-file.php" set as action:

<form action="accept-file.php" method="post" enctype="multipart/form-data">

This is where the form data will be sent to via the set method (POST in this case) and using the given encoding type.

After you click on "submit" your browser will call this script, which in your case does not exist. Therefore your webserver will return the error message instead of handling the upload.

To make it work you need to change the action to the filename of your script, which you have posted above.

SDwarfs
  • 3,189
  • 5
  • 31
  • 53