使用PHP上传文件并添加MySQL数据库的路径
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用PHP上传文件并添加MySQL数据库的路径,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2647字,纯文字阅读大概需要4分钟。
内容图文
![使用PHP上传文件并添加MySQL数据库的路径](/upload/InfoBanner/zyjiaocheng/911/e4381ec322d74f40be9c843ddc41141e.jpg)
upload.php的:
<?php
//This is the directory where images will be saved
$target = "pics";
$target = $target . basename( $_FILES['Filename']['name']);
//This gets all the other information from the form
$Filename=$_POST['Filename'];
$Description=$_POST['Description'];
$pic=($_FILES['Filename']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("altabotanikk") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO picture (Filename,Description)
VALUES ('$Filename', '$Description')") ;
//Writes the Filename to the server
if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['Filename']). " has been uploaded, and your information has been added to the directory";
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
这是表单(在单独的文件中):
<form method="post" action="upload.php" enctype="multipart/form-data">
<p>Photo:</p>
<input type="file" name="Filename">
<p>Description</p>
<textarea rows="10" cols="35" name="Description"></textarea>
<br/>
<input TYPE="submit" name="upload" value="Add"/>
</form>
错误是
Undefined index: Filename on Line 17
($Filename = $_ POST [‘Filename’];)
和
Undefined index: uploadedfile on Line 35
(回显“文件”.basename($_FILES [‘uploadedfile’] [‘Filename’]).“已上传,您的信息已添加到目录”;)
echo"<pre>".print_r($_FILES,true)."</pre>";
给我:
Array
(
[Filename] => Array
(
[name] => Laserkanon.jpg
[type] => image/jpeg
[tmp_name] => C:\WampServer\tmp\php11D4.tmp
[error] => 0
[size] => 41813
)
)
解决方法:
首先,您应该使用print_r($_ FILES)进行调试,并查看它包含的内容. :
你的uploads.php看起来像:
//This is the directory where images will be saved
$target = "pics/";
$target = $target . basename( $_FILES['Filename']['name']);
//This gets all the other information from the form
$Filename=basename( $_FILES['Filename']['name']);
$Description=$_POST['Description'];
//Writes the Filename to the server
if(move_uploaded_file($_FILES['Filename']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['Filename']['name']). " has been uploaded, and your information has been added to the directory";
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("altabotanikk") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO picture (Filename,Description)
VALUES ('$Filename', '$Description')") ;
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
内容总结
以上是互联网集市为您收集整理的使用PHP上传文件并添加MySQL数据库的路径全部内容,希望文章能够帮你解决使用PHP上传文件并添加MySQL数据库的路径所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。