PHP帖子的奇怪行为

PHP帖子的奇怪行为,php,Php,所以我看到了一个奇怪的行为,我问了一下,但这似乎是一个代码问题。问题是,当我使用MAMP在本地进行测试时,这段代码工作得很好,一旦我将它放在HostGator上,我就会发现这种奇怪的现象 所以这个过程是 上传文件 检查事物的状态 解压文件 读入数据文件 复制和缩略图像 将数据转储到数据库中 我知道会发生1到5次,因为我可以看到缩略图。奇怪的是,我从第二步得到一个错误,说文件没有上传。所以看起来整个过程都是从“空白”POST数据开始的 因此,步骤1是这段代码。当我的表格发布时,它被称为: func

所以我看到了一个奇怪的行为,我问了一下,但这似乎是一个代码问题。问题是,当我使用MAMP在本地进行测试时,这段代码工作得很好,一旦我将它放在HostGator上,我就会发现这种奇怪的现象

所以这个过程是

  • 上传文件
  • 检查事物的状态
  • 解压文件
  • 读入数据文件
  • 复制和缩略图像
  • 将数据转储到数据库中
  • 我知道会发生1到5次,因为我可以看到缩略图。奇怪的是,我从第二步得到一个错误,说文件没有上传。所以看起来整个过程都是从“空白”POST数据开始的

    因此,步骤1是这段代码。当我的表格发布时,它被称为:

    function action_upload() {
        $ownerName = $this->request->post('ownerName', '');
        $ownerEmail = $this->request->post('ownerEmail', '');
        $ownerPhone = $this->request->post('ownerPhone', '');
        $username = $this->request->post('username', '');
        $password = $this->request->post('password', '');
        $treeName = $this->request->post('treeName', '');
    
        $error = $this->util->process_datafile($ownerName, $ownerEmail, $ownerPhone, $username, $password, false, $treeName);
    
        if ($error != "") {
            echo json_encode(array(
                'error' => $error,
            ));
        } else {
            echo json_encode(array(
                'gotoURL' => "/" . $treeName,
            ));
        }
        exit;
    }
    
    该操作读取一些表单字段并调用一个函数
    process\u datafile
    ,该函数处理上传的文件。下面是这个函数,我收到的错误来自第9行,“没有提供树名”。但我知道它在某个时候会克服那个错误

    public function process_datafile($ownerName, $ownerEmail, $ownerPhone, $username, $password, $update, $treeName) {
    
        // Make sure we have a tree name
        if ($treeName != "") {
            $this->scriptPath = dirname(__FILE__);
            $this->treePath = dirname(dirname($this->scriptPath)) . "/assets/trees/" . $treeName . "/";
            $this->tempFilePath = dirname(dirname($this->scriptPath)) . "/assets/temp/" . $this->guid() . "/";
        } else {
            return "No tree name provided";
        }
    
        // Check to make sure the tree is in the expect condition
        $treeExists = false;
        if (file_exists($this->treePath)) {
            $treeExists = true;
        }
        if ($treeExists && !$update) {
            return "Tree name already exists " . $this->treePath;
        } else if (!$treeExists && $update) {
            return "Tree does not exists";
        }
    
        // Make sure there are no upload errors
        if ($_FILES['treeFile']['error'] == '1' || $_FILES['treeFile']['error'] == '2') {
            return "File size to large, try to upload your tree without media.";
        } else if ($_FILES['treeFile']['error'] != '0') {
            return "File upload error: " . $_FILES['treeFile']['error'];
        }
    
        // Move the uploaded file
        if (!file_exists($this->tempFilePath)) {
            mkdir($this->tempFilePath, 0700, true);
        }
        $name = $_FILES["treeFile"]["name"];
        $tempfile = $this->tempFilePath . $name;
        copy($_FILES['treeFile']['tmp_name'], $tempfile);
    
    
        // Make sure it is something we can deal with
        $finfo = finfo_open(FILEINFO_MIME);
        $fileparts = explode(";", finfo_file($finfo, $tempfile));
        $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
        $filetype = $fileparts[0];
        $valid = "text/plain,image/png";
        if (($filetype != "text/plain" && $filetype != "application/zip") || ($ext != "ged" && $ext != "zip")) {
            return "Only gedcom (.ged) or archive (.zip) files may be uploaded.";
        }
    
        $gedfile = $tempfile;
        $archive_tmp = "";
        if ($filetype == "application/zip" && $ext == "zip") {
            $archive_tmp = $this->tempFilePath . "archive/";
            if (!file_exists($archive_tmp)) {
                mkdir($archive_tmp, 0700, true);
            }
    
            // Extract the archive
            $zip = new \ZipArchive;
            $res = $zip->open($tempfile);
            if ($res === TRUE) {
                $zip->extractTo($archive_tmp);
                $zip->close();
            } else {
                $this->delTree($archive_tmp);
                return "Error processing archive";
            }
    
            // Find the gedcom
            $found = false;
            $it = new \RecursiveDirectoryIterator($archive_tmp);
            foreach(new \RecursiveIteratorIterator($it) as $file)
            {
                $file_ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                if (strtolower($file_ext) == "ged") {
                    $gedfile = $file;
                    $found = true;
                }
            }
    
            if (!$found) {
                $this->delTree($archive_tmp);
                return "Could not find gedcom (.ged) file in archive.";
            }
        }
    
        // Make the tree folder if needed
        if (!file_exists($this->treePath)) {
            mkdir($this->treePath, 0700, true);
        }
            $this->mediaPath = $this->treePath . "media/";
        $this->delTree($this->mediaPath);
        if (!file_exists($this->mediaPath)) {
            mkdir($this->mediaPath, 0700, true);
        }
        if (file_exists($this->treePath . "tree.ged")) {
            unlink($this->treePath . "tree.ged");
        }
        copy($gedfile, $this->treePath . "tree.ged");
    
    
        // Deal with the database
        if (!$this->create_database($ownerName, $ownerEmail, $ownerPhone, $username, $password, $update)) {
            return "Could not open database";
        }
    
        // Process the gedcom
        $this->process_gedcom($this->mediaPath, $archive_tmp);
    
        // Remove the temp folder
        $this->delTree($this->tempFilePath);
    
        return "";
    }
    
    我知道在某个时候,它会进入
    过程\u gedcom
    ,因为在那里会发生缩略图。。。我也知道它永远不会进入到
    foreach($ged->people as$person)
    ,因为数据库中没有条目

    private function process_gedcom($mediaPath, $archivePath) {
        // Insert statements
        $personInsert = "INSERT INTO people   (id, gender, first, last, middle, title, suffix) VALUES (:id, :gender, :first, :last, :middle, :title, :suffix)";
        $nameInsert   = "INSERT INTO names    (personID, `type`, first, last) VALUES (:id, :type, :first, :last)";
        $familyInsert = "INSERT INTO families (id, personAID, personBID) VALUES (:id, :personAID, :personBID)";
        $childInsert  = "INSERT INTO children (familyID, `type`, personID) VALUES (:familyID, :type, :personID)";
        $eventInsert  = "INSERT INTO events   (personID, familyID, `type`, date, place, description) VALUES (:personID, :familyID, :type, :date, :place, :description)";
        $factInsert   = "INSERT INTO facts    (personID, name, value) VALUES (:personID, :name, :value)";
        $mediaInsert  = "INSERT INTO media    (id, file, `type`, title) VALUES (:id, :file, :type, :title)";
        $peopleMediaInsert = "INSERT INTO people_media (mediaID, personID) VALUES (:mediaID, :personID)";
        $familyMediaInsert = "INSERT INTO family_media (mediaID, familyID) VALUES (:mediaID, :familyID)";
    
    
        // Load in the gedcom file
        $ged = new \App\Gedcom();
        $ged->import($this->treePath . "tree.ged", array($this, 'log'));
    
    
        // Add objects to the database
        foreach ($ged->objects as $obj) {
            $file = $this->findFile($obj->getFilename(), $archivePath);
            if ($file !== false) {
                $finfo = finfo_open(FILEINFO_MIME);
                $fileparts = explode(";", finfo_file($finfo, $file));
                $filetype = $fileparts[0];
                $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                $hash = md5_file($file);
                copy($file, $mediaPath . $hash . "." . $ext);
                $this->makeThumb($mediaPath . $hash . "." . $ext, 200, 200, "thumb");
                $this->makeThumb($mediaPath . $hash . "." . $ext, 1024, 768, "resized");
                $this->database($mediaInsert, array(':id'    => $obj->getId(),
                                                    ':file'  => $hash . "." . $ext,
                                                    ':type'  => $filetype,
                                                    ':title' => $obj->getTitle()));
            }
        }
    
        // Add people to the databsse
        foreach ($ged->people as $person) {
            $this->database($personInsert, array(':id'     => $person->getId(),
                                                 ':gender' => $person->getGender(),
                                                 ':first'  => $person->getFirstName(),
                                                 ':last'   => $person->getLastName(),
                                                 ':middle' => $person->getMiddleName(),
                                                 ':title'  => $person->getTitleName(),
                                                 ':suffix' => $person->getSuffixName()));
    
    更多数据插入


    什么会导致事情重新启动,因为它看起来像是调用了两次
    process\u datafile
    ,一次是有效输入,第二次是“空白”

    只要在第9行回显堆栈跟踪,它会告诉您调用来自何处我不确定这在您的情况下是否正确,但这一次,我有了一个带有jQuery的幻灯片放映插件,它可以按需加载图像。每当它试图加载某些东西时,我的整个路由系统都会触发我的一些功能,因为我的系统架构已经损坏。我的猜测可能是,有一个脚本再次触发了你的整个过程,它没有发送任何东西,因为它正在运行。我用Firebug中的
    Net
    层跟踪了这一点。