Pergunta

code is to store the image nto the database the database structure is

enter image description here

if(!isset($_POST['upload']))
  {
echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="file" name="image"/>';
echo '<input type="submit" name="upload" value="upload"/>';
echo '</form>';
   }
 else
   {
$upload='images/';
$name=$_FILES['image']['name'];
$tempname=$_FILES['image']['tmp_name'];
$filesize=$_FILES['image']['size'];
$filetype=$_FILES['image']['type'];
$path=$upload.$name;
$result=move_uploaded_file($tempname, $path);
if(!$result)
{
    echo "error";
}
$sql="INSERT INTO imaget(name,image) VALUES('$name','$path')";
if(($conn->query($sql))==true)
{
    $sql="SELECT * FROM imaget";
    if(($img=$conn->query($sql))==true)
    {
        echo "success";
    }
}
else
{
    echo "error in upload into database";
}
    }

it shows warning like this

Warning: move_uploaded_file(images/20140302_210804.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\new\image.php on line 18

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php2923.tmp' to 'images/20140302_210804.jpg' in C:\xampp\htdocs\new\image.php on line 18

errorsuccess

why it shows warning and how to solve the warning anyone help me?

Foi útil?

Solução

Why it shows warning?

Because it could not move the file move 'C:\xampp\tmp\php2923.tmp' to 'images/20140302_210804.jpg

Upload always put your file first to a temporary position, and then you are responsible to move it to the right position.

Maybe you should provide an absolute path in $upload. If error still there, you can check your filesystem. If error still there, use php file functions to see if php can read and write the directories.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top