Problems with uploading file

Ben Source

I need to upload a file securely.

I use the following code:

if (is_uploaded_file($_FILES["resume_file"]["tmp_name"]) && $_FILES["resume_file"]["size"]) {
    $upload_name = $_FILES['resume_file']['tmp_name'];
    $cat = $_SERVER["DOCUMENT_ROOT"].'/up_resume';

    if(is_uploaded_file($upload_name)){
        $new_upload_name = $cat.'/user';

        switch ($_FILES['resume_file']['type']){
            case 'application/msword':
            $cat .= '-document.doc';
            break;

            case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
            $cat .= '-documentx.docx';
            break;

            case 'application/pdf':
            $cat .= '-document.pdf';
            break;

            default:
            echo 'File not supported';
            exit;
        }
        if (move_uploaded_file($upload_name, $cat)){
            echo 'Success upload with name'. $cat;
            @chmod($cat, 0644);
        }
        else{
            echo 'Error upload';
        }
        $xml_exp .= '<file>'.htmlspecialchars($upload_fname).'</file>';
        $message .= $loc['form']['data']['resume_file']['#text'].': http://' . $_SERVER['HTTP_HOST'] . '/up_resume/' . $code.'.'.$ext;
    }
}

When I push the "submit" button, the file doesn't get uploaded.

phpsecurityfile-upload

Answers

comments powered by Disqus