Php 如何在脚本中再添加2个文件上传,从而允许将文件名发送到数据库,将文件发送到目录
嘿,伙计们,我一直在尝试改变这个upload.php,我对这个很陌生。我需要添加两个以上的文件上传字段的脚本,以便我可以上传3个图像到数据库中,在那里我可以呼出文件名的帖子,并保存到文件到一个目录,我不知道如何改变下面的代码,以适应Php 如何在脚本中再添加2个文件上传,从而允许将文件名发送到数据库,将文件发送到目录,php,mysql,file-upload,Php,Mysql,File Upload,嘿,伙计们,我一直在尝试改变这个upload.php,我对这个很陌生。我需要添加两个以上的文件上传字段的脚本,以便我可以上传3个图像到数据库中,在那里我可以呼出文件名的帖子,并保存到文件到一个目录,我不知道如何改变下面的代码,以适应 upload.php <?php $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect:
upload.php
<?php
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_selectdb("tutorials_upload");
if(!is_dir("uploads")){//do we need to make the uploads directory for the files?
mkdir("uploads");//make the rest of the script safe, though this will only be done once
}
function savedata(){
global $_FILES, $_POST, $putItAt;
$sql = "INSERT INTO `tutorials_upload`.`thefiles` (
`ID` ,
`Time` ,
`FileLocation` ,
`IP` ,
`Title`
)
VALUES (
NULL , UNIX_TIMESTAMP( ) , '".mysql_real_escape_string($putItAt)."', '".$_SERVER['REMOTE_ADDR']."', '".mysql_real_escape_string($_POST['Title'])."'
);";
mysql_query($sql);
}
$putItAt = "uploads/".basename($_FILES['uploadedfile']['name']);
$putItAt = str_replace("php","txt", $putItAt);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$putItAt)){
savedata();
header("location: listfiles.php");//redirect them to the listfiles.php page
}else{
if(copy($_FILES['uploadedfile']['tmp_name'],$putItAt)){
savedata();
header("location: listfiles.php");
}else{
echo 'You totally failed. click <a href="index.php">here</a> to go back and try again.';
}
}
?>
我想将FileLocation2和FileLocation3添加到数据库中
表格是
<form enctype="multipart/form-data" action="upload.php" method="post">
Choose your file to upload!
<input name="uploadedfile" type="file" />
<br />
And what would you like to call it? <input name=“title” type=“text” />
<input type="submit" value="upload file"/>
</form>
我需要做的是在表单中再添加两个文件上传字段,并将文件名发布到另外两个图像名字段中,我将把它们放到数据库中,谢谢各位的帮助
<form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
也许还有一些文本字段,如果我能成为那个暴徒的傻瓜,但我不知道如何把你的答案放到上传的php文件中,我对php很陌生,再次感谢你,伙计
<form action="file-upload.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
foreach ($_FILES['image']['name'] as $i => $name) { }