如何使用PHP和mysql在特定文件夹中保存图像? [英] How can I save image in particular folder using PHP and mysql?
本文介绍了如何使用PHP和mysql在特定文件夹中保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将图片保存在图片文件夹中。
注意:未定义索引:img in C:\ xampp \ htdocs \ image \ index。第9行的PHP
注意:未定义的索引:第14行的C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\ b $ b每次都会显示此错误。
我尝试了什么:
dbconfig.php
<?php
//此处定义的所有变量都可以在包含此$ $的所有文件中访问b $ b $ con = new mysqli('localhost','root','','project')或die(无法连接到mysql.mysqli_error($ con));
mysqli_select_db($ con,image);
?>
INDEX.PHP
包括( 'dbconfig.php');
if(isset($ _ POST ['submit']))
{
$ name = $ _ POST ['name'];
$ img = $ _ FILES ['img'] ['name'];
$ result =插入图片值('null','$ name','$ img');
if(mysqli_query($ con,$ result))
{
move_uploaded_file($ _ FILES ['image'] ['temp_name'],picture / $ img);
echo< script>
alert('image upload to folder')
< / script>;
}
其他
{
echo< script>
alert('图片不上传到文件夹')
< / script>;
}
}
?>
< html>
< head>
< title>图片使用php< / title>上传到文件夹
< / head>
< body>
< form action =index.phpmethod =postenctype =mutlipart / form-data>
< label> name:< / label>
< input type =textname =name>< br>< br>
< br>
< label>选择要上传的图片:< / label>
< input type =filename =img>< br>
< input type =submitname =submitvalue =upload picture>
< / form>
< / body>
< / html>
解决方案
con = new mysqli('localhost','root','',' project')或die(无法连接到mysql.mysqli_error(
con));
mysqli_select_db(
con,image);
?>
INDEX.PHP
包括( 'dbconfig.php');
if(isset(
i am trying to save image in the picture folder .
Notice: Undefined index: img in C:\xampp\htdocs\image\index.php on line 9 Notice: Undefined index: image in C:\xampp\htdocs\image\index.php on line 14
this error is shown every time.
What I have tried:
dbconfig.php <?php //all the variables defined here are accessible in all the files that include this one $con= new mysqli('localhost','root','','project') or die("Could not connect to mysql".mysqli_error($con)); mysqli_select_db($con,"image"); ?>
INDEX.PHP
include('dbconfig.php'); if (isset($_POST['submit'])) { $name=$_POST['name']; $img=$_FILES['img']['name']; $result="INSERT into images values('null','$name','$img')"; if (mysqli_query($con, $result)) { move_uploaded_file($_FILES['image']['temp_name'], "picture/$img"); echo "<script> alert('image upload to folder') </script>"; } else { echo "<script> alert('image does not upload to folder') </script>"; } } ?> <html> <head> <title>image upload into folder using php</title> </head> <body> <form action="index.php" method="post" enctype="mutlipart/form-data"> <label>name:</label> <input type="text" name="name"><br><br> <br> <label>select image to upload:</label> <input type="file" name="img"><br> <input type="submit" name="submit" value="upload picture"> </form> </body> </html>解决方案con= new mysqli('localhost','root','','project') or die("Could not connect to mysql".mysqli_error(
con)); mysqli_select_db(
con,"image"); ?>
INDEX.PHP
include('dbconfig.php'); if (isset(
这篇关于如何使用PHP和mysql在特定文件夹中保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文