duanfan8360 2013-11-05 02:22
浏览 127

消除错误4 UPLOAD_ERR_NO_FILE /不要

I have a code which allows file upload. It throws an error handler when it encounters Show Error 4 UPLOAD_ERR_NO_FILE. function error and error array and some code below it is responsible for that. what i want is to ELIMINATE THAT ERROR AND MAKE IT JUST FINE WHEN NO FILE IS UPLOADED. meaning, the code still continues to process even with no uploaded file. How can I do that? it burdened me for many days now. please extend a help, or share this to someone you know can help. thank you very much.

Index.php

    <?php
    // make a note of the current working directory relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

    // make a note of the location of the upload handler
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'processor.php';

    // set a max file size for the html upload form
    $max_file_size = 30000; // size in bytes

    // now echo the html page
    ?>

    <!DOCTYPE html>
    <html class="html">
     <head>
         <div class="container">
        <form action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">

        SOME HTML CODE HERE 

        </form>
    </div>
    </head>
    </html>

Processor.php

$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['submit'])
        or error('the upload form is neaded', $uploadForm);

    // check for standard uploading errors
    ($_FILES[$fieldname]['error'] == 0)
        or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

    @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
        or error('not an HTTP upload', $uploadForm);

    @getimagesize($_FILES[$fieldname]['tmp_name'])
        or error('only image uploads are allowed', $uploadForm);

    $now = time();
    while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
        $now++;
    }

    // now let's move the file to its final and allocate it with the new filename
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or error('receiving directory insuffiecient permission', $uploadForm);

    $name = $_POST['name'];
    $email = $_POST['email'];
    $office_id = $_POST['office_id'];

    $get_title = $_POST['title'];
    $title = strtoupper ($get_title);
    $namehere = "Super Story By " .$_POST['name'];
    $story =  $_POST['story'];
    header('Content-Type: image/jpeg');


    $upload = $uploadFilename;
    $im = imagecreatefromjpeg("bg.jpg");
    $img2 = imagecreatefromjpeg($upload);
    $black = imagecolorallocate($im, 0, 0, 0);
    $font = 'arialbi.ttf';
    $font2 = 'ariali.ttf';
    /*SOME MORE IMAGETTFTEXT CODE HERE*/
    imagedestroy($im);


    if (!empty($name) && !empty($email) && !empty($office_id) && !empty($title) && !empty($story)) {
        SOME QUERY HERE
    }


    function error($error, $location, $seconds = 5)
    {
        header("Refresh: $seconds; URL=\"$location\"");
        echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."
".
        '"http://www.w3.org/TR/html4/strict.dtd">'."

".
        '<html lang="en">'."
".
        '   <head>'."
".
        '       <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."

".
        '       <link rel="stylesheet" type="text/css" href="stylesheet.css">'."

".
        '   <title>Upload error</title>'."

".
        '   </head>'."

".
        '   <body>'."

".
        '   <div id="Upload">'."

".
        '       <h1>Upload failure</h1>'."

".
        '       <p>An error has occured: '."

".
        '       <span class="red">' . $error . '...</span>'."

".
        '       The upload form is reloading</p>'."

".
        '    </div>'."

".
        '</html>';
        exit;
    } // end error handler

I tried just deleting the function error but it's not working well when i d that. hope you can help me with this. I really need to make it work. Thank you in advance for helping me sort it out. :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料