How to upload an image in php mysql -
hi iam trying upload image database inserting tmp_name in database.can me .
here code
<?php $connection = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("accountant", $connection); $title=$_post['blog_title']; $description=$_post['blog_description']; $name=$_files["image"]["tmp_name"]; $type=$_files["image"]["type"]; $size=$_files["image"]["size"]; $temp=$_files["image"]["tmp_name"]; $error=$_files["image"]["error"]; if($error>0) die("error while uploading"); else { if($type == "image/png" || $type == "image/jpeg" ||$type == "image/jpg" || $type == "image/svg" || $size >2000000) { move_uploaded_file($temp,"upload/".$name); $sql=mysql_query("insert blogs(image,blog_title,blog_description)values('$name','$title','$description')"); echo "upload complete"; } else { die("format not allowed or file size big!"); } }
iam trying insert image getting errors
warning: move_uploaded_file(upload/c:\xampp\tmp\php1908.tmp): failed open stream: invalid argument in c:\xampp\htdocs\accounting\admin\blogs.php on line 21
warning: move_uploaded_file(): unable move 'c:\xampp\tmp\php1908.tmp' 'upload/c:\xampp\tmp\php1908.tmp'
in database inserting c:xampp mpphp1908.tmp
<?php $connection = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("accountant", $connection); $title=$_post['blog_title']; $description=$_post['blog_description']; $name=$_files["image"]["name"]; $type=$_files["image"]["type"]; $size=$_files["image"]["size"]; $temp=$_files["image"]["tmp_name"]; $error=$_files["image"]["error"]; if($error>0) die("error while uploading"); else { if($type == "image/png" || $type == "image/jpeg" ||$type == "image/jpg" || $type == "image/svg" || $size >2000000) { move_uploaded_file($temp,"upload/".$name); $sql=mysql_query("insert blogs(image,blog_title,blog_description)values('$name','$title','$description')" ); echo "upload complete"; } else { die("format not allowed or file size big!"); } }
Comments
Post a Comment