php网站数据库文件名,在使用PHP将图像上传到服务器时,如何在数据库中存储文件名以及其他信息?...

这篇博客介绍了一个PHP脚本,用于处理HTML表单数据,包括乐队成员信息和照片上传。照片将以成员名字命名并保存在指定目录,同时信息会被存储到MySQL数据库中。如果文件名重复,旧文件将被新文件覆盖,且文件大小限制为35kb。该脚本首先连接到数据库,然后插入表单数据,最后将照片上传到服务器。
摘要由CSDN通过智能技术生成

这是您在我看来遍及网络上试图找出如何完成此任务的那些人的答案。使用存储在mysql数据库中的文件名以及您想要在数据库中的其他表单数据将照片上传到服务器。请让我知道是否有帮助。

首先,您需要的表格:

Please Enter the Band Members Name.

Band Member or Affiliates Name:

Please Enter the Band Members Position. Example:Drums.

Band Position:

Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.

Photo:

Please Enter any other information about the band member here.

Other Member Information:

Please Enter any other Bands the Member has been in.

Other Bands:

然后,这段代码将处理来自表单的数据:

// This is the directory where images will be saved

$target = "your directory";

$target = $target . basename( $_FILES['photo']['name']);

// This gets all the other information from the form

$name=$_POST['nameMember'];

$bandMember=$_POST['bandMember'];

$pic=($_FILES['photo']['name']);

$about=$_POST['aboutMember'];

$bands=$_POST['otherBands'];

// Connects to your Database

mysqli_connect("yourhost", "username", "password") or die(mysqli_error()) ;

mysqli_select_db("dbName") or die(mysqli_error()) ;

// Writes the information to the database

mysqli_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)

VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

// Writes the photo to the server

if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))

{

// Tells you if its all ok

echo "The file ". basename( $_FILES['uploadedfile']['name']). " 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.";

}

?>

从www.about.com编辑的代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值