Reputation: 121
I have a a multifile upload script that converts uploaded files to zip. It works flawlessly.Only problem that I have is uploading data to the database. I tried everything and the databse still doesn't get any of the data. Two things: 1: I want to send the file path within a html link tag to be displayed as a link on the page I will be loading to and 2: the rest of the data as is submitted on the form. Any help would be great. Here is the code:
<?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')");
Upvotes: 0
Views: 140
Reputation: 5996
Like nvanesch said use mysqli
for creating connection.
Also you have to put the variable values into quotes:
Try like this:
$sql = "INSERT INTO demo (`name`, `id_continent`, `lastvisit`, `cdate`, `ddate`, `email`)
VALUES ('".$project."', '".$assignto."','".$asdate."','".$chdate."','".$ddate."')";
mysqli_query($sql);
Upvotes: 4
Reputation: 2600
You are connecting with mysql_ and next querying with mysqli_
You should either have all with mysql_ (not recommended as mysql_ is deprecated) or use mysqli_ everywhere.
Upvotes: 0