Jump to content

Help with image upload ?


cyber_alchemist
Go to solution Solved by Ch0cu3r,

Recommended Posts

I was writing a code which check whether the file upload was successful or not or the file/image is of supported type or not. The script though always returns a error of 'invalid file type' even if i upload the correct file type. what could be the the plausible causes for it ?? do i have a error in my code or something else ?? here is the code.

if ( isset( $_POST[ 'submit' ] ) ) {
                        $dir_1   = './images/';
                        $thumb_1 = '.images/thumb';
                        //making sure the uploaded file transfer was successful
                        if ( $_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK ) {
                                switch ( $_FILES[ 'pic1' ][ 'error' ] ) {
                                        case UPLOAD_ERR_INI_SIZE:
                                                die( 'The uploaded 1st image exceeds the upload_max_filesize directive ' . 'in php.ini.' );
                                                break;
                                        case UPLOAD_ERR_FORM_SIZE:
                                                die( 'The uploaded 1st exceeds the MAX_FILE_SIZE directive that ' . 'was specified in the HTML form.' );
                                                break;
                                        case UPLOAD_ERR_PARTIAL:
                                                die( 'The uploaded 1st image was only partially uploaded.' );
                                                break;
                                        case UPLOAD_ERR_NO_FILE:
                                                die( 'No 1st image was uploaded.' );
                                                break;
                                        case UPLOAD_ERR_NO_TMP_DIR:
                                                die( 'The server is missing a temporary folder.' );
                                                break;
                                        case UPLOAD_ERR_CANT_WRITE:
                                                die( 'The server failed to write the uploaded the uploaded 1st image to disk.' );
                                                break;
                                        case UPLOAD_ERR_EXTENSION:
                                                die( '1st image upload stopped by extension.' );
                                                break;
                                } //$_FILES[ 'pic1' ][ 'error' ]
                        } //$_FILES[ 'pic1' ][ 'error' ] != UPLOAD_ERR_OK
                        // making sure the file is being uploaded

                        $error = 'The 1st image you have uploaded either was not of supported filetype.';
                        switch ( $type ) {
                                case IMAGETYPE_GIF:
                                        $image_1 = imagecreatefromgif( $_FILES[ 'pic1' ][ 'tmp_name' ] ) or die( $error );
                                        break;
                                case IMAGETYPE_JPEG:
                                        $image_1 = imagecreatefromjpeg( $_FILES[ 'pic1' ][ 'tmp_name' ] ) or die( $error );
                                        break;
                                case IMAGETYPE_PNG:
                                        $image_1 = imagecreatefrompng( $_FILES[ 'pic1' ][ 'tmp_name' ] ) or die( $error );
                                        break;
                                default:
                                        die( $error );                                        
                        } //$type
                          $image_date_1 = @date( 'Y-m-d' );
                         list( $width, $height, $type, $attr ) = getimagesize( $_FILES[ 'pic1' ][ 'tmp_name' ] );

}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.