0

I have a html code as below through which I give image file as input

 <input name="photo_file" type="file" />

then anather php file to insert record into database code is as below

<?php
define('GW_UPLOADPATH', 'images/');
$picture=$_FILES['photo_file'];
$target= GW_UPLOADPATH . $picture ;

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("demo", $con);
if (move_uploaded_file($_FILES['photo_file']['tmp_name'], $target))
{
mysql_query("INSERT INTO feedback (photo)VALUES ('".$picture."')");


echo "record inserted";
}
mysql_close($con);
?> 

I got error as below
Notice: Undefined index: photo_file in C:\wamp\www\shilpa\send.php on line 3

will anybody help me I tried all possible ways:( now needs help Thank you in advance

4
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by jacob.lemelincarrier
0

$_FILES['photo_file'] does not exist for some reason. Good practice is to check for existance first:

if(!isset($_FILES['photo_file'])) {

    // handle the wrror the way you see fit
    die('Error uploading the file');
}

// code for normal processing
0

Line 3 should get the name of the file instead of the array:

$picture=$_FILES['photo_file']['name'];  // Gets the original file name.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.