dongwu8050 2018-03-12 04:29
浏览 68

从每个上传的html php文件中分别出现错误警告

Sorry for the messy code, I'm just a newbie.

How can I separate the error of each file uploaded so that I can make different html code?

switch ( $_FILES['photo']['error'][$key] ) {
    case UPLOAD_ERR_NO_FILE:
        $photo_errors0[0] = 'No file sent';
        $photo_errors1[1] = 'No file sent';
        break;
    case UPLOAD_ERR_INI_SIZE:
    case UPLOAD_ERR_FORM_SIZE:
        $photo_errors0[0] = 'Max file size exceeded!';
        $photo_errors1[1] = 'Max file size exceeded!';
        break;
    default:
        $photo_errors0[0] = 'Unknown errors';
        $photo_errors1[1] = 'Unknown errors';
        break;
}

<?php foreach ($photo_errors0 as $photo_error0):?>
    <div class="photo-error"><?php echo htmlspecialchars( $photo_error0 ); ?></div>
<?php endforeach; ?>
<?php foreach ($photo_errors1 as $photo_error1):?>
    <div class="photo-error"><?php echo htmlspecialchars( $photo_error1 ); ?></div>
<?php endforeach; ?>
  • 写回答

1条回答 默认 最新

  • dqtok88424 2018-03-12 04:49
    关注

    before my code is, this is work but if 2 files error the errors show at once, i'm trying to separate the error from the each file so can make easyli on html. thx

    switch ( $_FILES['photo']['error'][$key] ) {
                    case UPLOAD_ERR_NO_FILE:
                        $photo_errors[] = 'No file sent';
                        break;
                    case UPLOAD_ERR_INI_SIZE:
                    case UPLOAD_ERR_FORM_SIZE:
                        $photo_errors[] = 'Max file size exceeded!';
                        break;
                    default:
                        $photo_errors[] = 'Unknown errors';
                        break;
    
    <?php foreach ($photo_errors as $photo_error):?>
    <div class="photo-error"><?php echo htmlspecialchars( $photo_error ); ?></div>
    <?php endforeach; ?>
    
    评论

报告相同问题?