Page 1 of 1

Moving images in PHP

Posted: 27 Sep 2011, 17:52
by Shelv
Hey guys & girls

I'm trying to move images in php but it's not working.

Code: Select all

<?php
                                            if (isset($_POST['submit'])) {
                                                if ((($image_type == 'image/jpg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/bmp') || ($image_type == 'image/gif'))
                                                      && ($image_size > 0) && ($image_size <= MYWORLD_MAXFILESIZE)) {
                                                    // Move file to upload target folder
                                                    $target = MYWORLD_UPLOADPATH . $image;
                                                    if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {
                                                        echo 'Image uploaded successfully';
                                                    } else {
                                                        $errors[] = 'Failed to move the uploaded file';
                                                        echo 'Failed to move the uploaded file';
                                                    }
                                                } else {
                                                    $errors[] = 'Only jpeg, bmp or gif files allowed to a maximum size of 1mb';
                                                    echo 'Only jpeg, bmp or gif files allowed to a maximum size of 1mb';
                                                }
                                            }
                                            ?>
I always get the last echo no matter what file type or size of the file.

Any help would be much appreciated :)

Re: Moving images in PHP

Posted: 28 Sep 2011, 09:50
by RuadRauFlessa
do an echo of $image_type at the top before

Code: Select all

if ((($image_type == 'image/jpg') || ($image_type == 'image/pjpeg') || ($image_type == 'image/bmp') || ($image_type == 'image/gif'))
and check what it is. Looks like you might want to change the values you are looking for.