0

私はこれを持っています。代わりにexit;、エコー後に実行されている関数を停止する別の方法があるのだろうか?

私の状況では、使用できない理由exit;は、エコーが別のウィンドウで発生し、ブラウザの戻るボタンを押して元のページに戻る必要があるためです。しかし、メッセージを削除exit;すると同じページに印刷されますが、特定のメッセージではなく、配列内のすべてのメッセージがシーケンスに従って画面に印刷されます。

では、どのような解決策を提案できますか?

    <?php
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$max_file_size = 3500000; // size in bytes

if(isset($_POST['submitForm']))
{
    if(!isset($_POST['chkOne']))
    {$ErrMsg = 'Tick the check box if you wish to upload images!';} 
    else{
    /*-------START------- */

$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';
$uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'index.php';
$uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';

$fieldname = 'file';

    function error($error, $location, $seconds = 5)
    {

        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
        '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
        '<html lang="en">'."\n".
        '   <head>'."\n".
        '       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
        '       <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
        '   <title>Upload error</title>'."\n\n".
        '   </head>'."\n\n".
        '   <body>'."\n\n".
        '   <div id="Upload">'."\n\n".
        '       <h1>Upload failure</h1>'."\n\n".
        '       <p>An error has occured: '."\n\n".
        '       <span class="red">' . $error . '...</span>'."\n\n".
        '       The upload form is reloading</p>'."\n\n".
        '    </div>'."\n\n".
        '</html>';

    } 
    $errors = array(1 => 'php.ini max file size exceeded', 
                    2 => 'html form max file size exceeded', 
                    3 => 'file upload was only partial', 
                    4 => 'no file was attached');

// check the upload form was actually submitted else print form
isset($_POST['submitForm'])
    or error('the upload form is neaded', $uploadForm);

// some code //

$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
    $now++;
}
$ErrMsg = "<b>Congratulations! Your file upload was successful</b>";

    /*-------END------- */
        }
}

?>
<!doctype html>
<html>
<head>
</head>

<body>
       <form id="Upload" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
           <table name="loadertable" width="394" border="1">
            <td>Upload image :</td>
              <td>
                    <div id="upload_title_text"><input type="checkbox" name="chkOne" id="chkOne">Upload these images:</div>
                    <div id="FileUploadDiv" DivValue="0">
                    <input id="file" type="file" name="file">
                    </div>
                    <input type="hidden" value="0" id="counter" name="counter">
                    <div align='left'></div>
        <p>
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
        </p>
              </td>
              <tr>
              <td>&nbsp;</td>
              <td><input id="submitForm" type="submit" name="submitForm" value="Preview"></td>
              </tr>
            <tr>
             <td><?php if(!empty($ErrMsg)) echo $ErrMsg; ?></td>
            </tr>
          </table>

        </form>

</body>
</html>
4

1 に答える 1