无法从不同目录上传文件

file.php - Here is a html code, which allows the user to select multiple files for uploading.

<html>  
<head>
    <meta charset="utf-8">
    <title></title>  
</head>  
<body>  
    <form method="post" enctype="multipart/form-data"  action="file2.php">  
        <input type="file" name="zipfile[]" multiple />  
        <br /><br />
        <button type="submit">Upload selected files</button>  
    </form>  
</body>  
</html>

file2.php - Here I tried to zip the multiple files which was selected before uploading, the problem is when I select the files for uploading from the current working directory, the files and zipped and uploaded. But when i select files from different directory other than the current working directory, files are not getting zipped and uploaded. thats the issue.

    <? $zeep = new ZipArchive;
$fyle = Array();
$zeep->open('zip/try.zip',  ZipArchive::CREATE);
foreach($_FILES['zipfile']['tmp_name'] as $fyl) {
    foreach($_FILES['zipfile']['name'] as $fyle) {

    echo $fyle;
    $zeep->addFile($fyl,$fyle);
    echo "<br/>";
}
}
$zeep->close();
?>

In the list of uploaded files, ['name'] is the filename as sent from the browser - it will usually be the filename on the remote user's machine. The reason this works with files in the current directory is that your server is able to see the same original files (it isn't using the uploaded data).

The file you need to add to the zip file is the one that has been uploaded to the server, the location of which is stored in ['tmp_name'].

From a comment on the manual page:

[name] => MyFile.txt 
(comes from the browser, so treat as tainted)

[tmp_name] => /tmp/php/php1h4j1o 
(could be anywhere on your system, depending on your config settings, 
but the user has no control, so this isn't tainted)

Edit: I'm not a PHP expert by any means, but I think the following will work:

<? $zeep = new ZipArchive;
$fyle = Array();
$zeep->open('zip/try.zip',  ZipArchive::CREATE);
foreach($_FILES['zipfile'] as $fyle) {

    echo $fyle['name'];
    $zeep->addFile($fyle['tmp_name'], $fyle['name']);
    echo "<br/>";
}
$zeep->close(); ?>

What this is doing, is using tmp_name as the file to add to the zip file, but specifying the bare name as the name to use within the zip file, otherwise you'd end up with the full temporary path within the archive.