PHP合并文件不起作用

时间:2014-03-18 13:13:15

标签: php

合并文件已经不再适用了,我不知道为什么。我没有收到任何屏幕上的错误,所以我检查了错误日志,这就是我所看到的:

[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/phplib/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Warning:  Invalid argument supplied for foreach() in /home/toolplas/public_html/main/phplib/edit_workorder.php on line 50, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Stack trace:, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/phplib/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Notice:  Undefined index: affect in /home/toolplas/public_html/main/phplib/edit_workorder.php on line 80, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Stack trace:, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/phplib/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Notice:  Undefined index: file in /home/toolplas/public_html/main/phplib/edit_workorder.php on line 282, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Stack trace:, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/phplib/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Warning:  Invalid argument supplied for foreach() in /home/toolplas/public_html/main/phplib/edit_workorder.php on line 282, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Stack trace:, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/phplib/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Warning:  mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/toolplas/public_html/main/edit_workorder.php on line 176, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP Stack trace:, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173
[Tue Mar 18 09:06:08 2014] [error] [client 10.0.50.12] PHP   1. {main}() /home/toolplas/public_html/main/edit_workorder.php:0, referer: https://new.tps.com/edit_workorder.php?job_num=1000&id=4173

它不是特定于一个工作订单,因为它发生在所有工作订单上,我不确定为什么它不再工作。

以下是代码:

if(isset($wo['files_to_merge'])){
    //$prev_files = $_POST['file'];
    //$files = $_FILES['file'];
    $folder = "/home/toolplas/public_html/main/pdf/temp/WO$wo_id/";
    if(!file_exists($folder)){
        mkdir($folder);
    }
    $files = array();
    if(isset($_POST['file'])){
        foreach($_POST['file'] as $key => $item){
            $files[] = array('order' => $key, 'filename' => $item);
        }
    }
    /*foreach($_FILES['file']['name'] as $key => $item){
        $name = date('U') . preg_replace('/[^\w\._]+/', '', basename($item));
        if(move_uploaded_file($_FILES['file']['tmp_name'][$key], $folder . $name)){
            $files[] = array('order' => $key, 'filename' => $name);
        } else {
            debug('File Not Uploaded ' . $name);
        }
    }*/
    foreach($_FILES['file']['error'] as $key => $error){
        $tmp_name= $_FILES['file']['tmp_name'][$key];
        $name = date('U') . preg_replace('/[^\w\._]+/', '', basename($_FILES['file']['name'][$key]));
        if($error == UPLOAD_ERR_OK){
            move_uploaded_file($tmp_name, $folder . $name);
            $files[] = array('order' => $key, 'filename' => $name);
        } else {
            debug("Cannot Move File: $tmp_name -> $name");
            debug("File Error: $error");
        }
    }
    $sql = "DELETE FROM workorder_files WHERE workorder_id = $wo_id;";
    echo $sql;
    mysqli_query($dbc3, $sql) or die("Query 11: " . mysqli_error($dbc3));
    foreach($files as $file){
        $sql = "INSERT INTO workorder_files(workorder_id, filename, `order`) VALUES($wo_id, '" . $file['filename'] . "', " . $file['order'] . ");";
        mysqli_query($dbc3, $sql) or die("Query 12: " . mysqli_error($dbc3));
    }
    //print_r($_FILES);
}

员工告诉我星期五和周末工作正常。

这就是表格的样子,

Form

HTML:

       <tr>
         <th>Files To Merge?</th>
           <td><input type="checkbox" class='files_to_merge' id="files_to_merge" name='workorder[files_to_merge]' {% if files is not empty %}checked='checked'{% endif %} />{{ functions.alert('More to the right') }}</td>
       </tr>
       <tr>
         <th>Posted By</th>
          <td>{{ user.name }}<input readonly="readonly" type="hidden" name="workorder[user]" value="{{ user.id }}" /></td>
       </tr>

0 个答案:

没有答案