我有一个多文件上传脚本,可将上传的文件转换为zip。它完美无缺。我只有将数据上传到数据库的问题。我尝试了一切,数据库仍然没有获得任何数据。两件事:1:我想在html链接标记内发送文件路径,在我要加载的页面上显示为链接,2:在表单上提交的其余数据。任何帮助都会很棒。这是代码:
<?php
set_time_limit(0); // Make sure php doesnt end script after 30 seconds
ini_set('memory_limit','128M');
ini_set( 'upload_max_filesize', '100M' );
ini_set( 'post_max_size', '100M' );
$project = $_POST['project'];
$assignto = $_POST['assignto'];
$asdate = $_POST['asdate'];
$chdate = $_POST['chdate'];
$ddate = $_POST['ddate'];
$timestamp = time();
if (isset ($_POST['submit']))
{
$filesArray= $_FILES["files"];
for ($num=0; $num<count($filesArray["name"]);$num++)
{
$fileName = $filesArray["name"][$num];
$tempName= $filesArray["tmp_name"][$num];
move_uploaded_file($tempName,"tmp/".$fileName);
}
$archiveName= $timestamp.".zip";
$filesArrayNames= $_FILES["files"]["name"];
$zipsDir= scandir ("uploads/");
$error = false;
foreach($zipsDir as $zipDirfile)
{
if($zipDirfile == $archiveName)
{
$error= true ;
break;
}
}
if ($error== false)
{
$tmpDir = scandir ("tmp/");
$zip = new ZipArchive;
$zip->open("uploads/".$archiveName, ZipArchive::CREATE);
for ($num =0; $num<count($filesArray["name"]);$num++)
{
$fileName = $filesArray["name"][$num];
foreach($tmpDir as $tmpDirfile)
{
if($tmpDirfile == $fileName)
{
$zip->addFile("tmp/".$fileName);
echo " Adding: ".$fileName."<br/>";
}
}
}
$zip->close();
for ($num=0; $num<count($filesArray["name"]);$num++)
{
$fileName = $filesArray["name"][$num];
foreach($tmpDir as $tmpDirFile)
{
if($tmpDirfile == $fileName)
{
unlink("tmp/".$fileName);
}
}
}
}
else
{
echo "Name already exists";
}
}
$filepath= "<a href='"'http://www.amadastage.com/uploads/ '"'.$archiveName.'"'>Files</a>';
mysql_connect("webcontrolcenter.com","dude","usa") or die ('Error:' .mysql_error());
//database connection
mysql_select_db("mediamanagement");
mysqli_query("INSERT INTO demo (name, id_continent, lastvisit,cdate,ddate,email)
VALUES ('project', 'assignto','asdate','chdate','ddate')");
答案 0 :(得分:4)
如nvanesch所说,使用mysqli
来创建连接
您还必须将变量值放入引号:
试试这样:
$sql = "INSERT INTO demo (`name`, `id_continent`, `lastvisit`, `cdate`, `ddate`, `email`)
VALUES ('".$project."', '".$assignto."','".$asdate."','".$chdate."','".$ddate."')";
mysqli_query($sql);
答案 1 :(得分:0)
您正在使用mysql_进行连接,然后使用mysqli _
进行查询你应该全部使用mysql_(不建议不推荐使用mysql_)或者在任何地方使用mysqli_。