Php图像/文件上传没有错误 - 白页

时间:2015-05-31 15:46:55

标签: php upload

我试图编写一个上传脚本,但我没有错误报告错误,只是一个空白屏幕,我检查了脚本,并且无法发现任何语法错误,据我所知 - 我知道哪个部分是导致错误但不确定原因?

这是第一个块,因为如果我删除它,表单会显示:

<?php # uploading files woooo


// CHECK IF THE FORM HAS BEEN SUBMITTED:
if (isset($_SERVER['REQUEST_METHOD'] == 'POST') {

    // CHECK FOR AND UPLOADED FILE:
    if (isset($_FILES['upload'])) {

        // VALIDATE THE TYPE. SHOULD BE JPEG OR PNG.
        $allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X_PNG', 'image/PNG', 'image/x-png');
        if (in_array($_FILES['upload']['type'], $allowed)) {

            // MOVE THE FILES OVER
            if (move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/{$_FILES['upload']['name']}")){
                echo '<p><em>the file has been uploaded</em></p>';
            } // END OF MOVE.... IF.

        } else { // INAVALID TYPE.
            echo '<p class="error">Please upload a JPEG or PN image.</p>';
        }

    }
}

脚本继续似乎没问题......

// CHECK FOR AN ERROR:

    if ($_FILES['upload']['error'] > 0) {
        echo '<p class="error">the file could not be uploaded because <strong>';

            // PRINT A MESSAGE BASED UPON THE ERROR

            switch ($_FILES['upload']['error']) {
                case 1:
                    print 'The file exceeds the upload_max filesize setting in php.ini';
                    break;
                case 2:
                    print 'The file exceeds the MAX_FILE_SIZE setting in the html form';
                    break;
                case 3:
                    print 'The file was only partially uploaded';
                    break;
                case 4:
                    print 'No file was uploaded';
                    break;
                case 6:
                    print 'No temp folder was available.';
                    break;
                case 7:
                    print 'Unable to write to the disk.';
                    break;
                case 8:
                    print 'File upload stopped.';
                    break;                      
                default:
                    print 'A system error occured';
                    break;

            } // END OF SWITCH

            print '</strong></p>';

        } // ENF OF ERROR IF

        // DELETE THE FILE IF STILL EXISTS

        if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name'])) {
            unlink ($_FILES['upload']['tmp_name']);

        } // ENF OF SUBMITTED FORM

    ?> 


<form enctype="multipart/form-data" method="post" action="info.php">

    <input type="hidden" name="MAX_FILE_SIZE" value="524288">

    <fieldset>
        <legend>Select a JPEG or PNG image of 512kb or smaller to be uploaded</legend>
        <p><b><input type="file" name="upload"></p>
    </fieldset>

    <div align="center"><input type="submit" name="submit" value="submit" /></div>


</form>

0 个答案:

没有答案