0

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')");
4

2 回答 2

4

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);
于 2013-05-06T07:19:37.220 回答
0

您正在使用 mysql_ 进行连接,接下来使用 mysqli_ 进行查询

您应该全部使用 mysql_(不推荐,因为不推荐使用 mysql_)或在任何地方使用 mysqli_。

于 2013-05-06T07:06:32.797 回答