Error Message shown after uploading file In PHP


I have a problem in my function:

        public uploadfile()
        //$tempFolder =$path."/tmp";
        $fileElementName = $folderId;

        if (!empty($_FILES[$fileElementName]['error'])) {
            switch($_FILES[$fileElementName]['error']) {
            case '1':
                $error = 'The uploaded file exceeds the upload_max_filesize "
                    ."directive in php.ini';
            case '2':
                $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive ".
                    ."that was specified in the HTML form';
            case '3':
                $error = 'The uploaded file was only partially uploaded';
            case '4':
                $error = 'No file was uploaded.';
            case '6':
                $error = 'Missing a temporary folder';
            case '7':
                $error = 'Failed to write file to disk';
            case '8':
                $error = 'File upload stopped by extension';
            case '999': 
                $error = 'No error code avaiable';
        } elseif (empty($_FILES[$fileElementName]['tmp_name']) 
            || $_FILES[$fileElementName]['tmp_name'] == 'none'
        ) {
            $error = 'No file was uploaded..';
        } else {
            if ($status==1) {
                if (!is_dir($path)) {
                    mkdir($path, 0777);

                if (!is_dir($path."/".$userloginId)) {
                    mkdir($path."/".$userloginId, 0777);

                if (!is_dir($path."/".$userloginId."/tmp")) {
                    mkdir($path."/".$userloginId."/tmp", 0777);

                if (move_uploaded_file(
                ) {
                    $msg= $_FILES[$fileElementName]['name'];
            } else {
                $error="File can not be uploaded because "
                    ."your Storage spacae capacity is exceed.<br/> "
                    ."Plese Contact with admin!";
    } else {
        $msg= "<script>window.location.href='".SITEURL."';</script>";
    echo "{";
        echo                "error: '" . $error . "',\n";
        echo                "msg: '" . $msg . "'\n";
        echo "}";


When I try to upload a file, the file is uploaded but still the messageNo file was uploaded. is displayed. Can anybody tell me the reason that when I upload a file it was uploaded to the Temp folder but after success it will still show the error messageNo file was uploaded.?




If you're not getting a file uploaded, then the chances are that your form is missing themultipart declaration.

Make sure that your<form> element contains theenctype="multipart/form-data" attribute.

Somethng like this:

<form action="...your-url-here..." enctype="multipart/form-data" method="post">

People are also looking for solutions to the problem: php - video file name doesn't load correctly


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.