Mirsad Batilovic
Mirsad Batilovic

Reputation: 441

Linux hosting file upload

I'm using Godaddy linux hosting and have a problem with uploading image on my website. Max file size that I want to allow for upload is 1mb and allow extensions jpg, jpeg, png and gif. I limit that with my PHP code. I can upload image smaller than 1mb and in that case it works fine. Image is uplaoded and data is stored in database. Also, when I try to upload image smaller than 2mb but bigger than 1mb my PHP code works ok and my code stop uploading file and display my warning that max allowed file size is 1mb. Also, everything work fine when I try to upload other file type that not allowed if it is smaller than 2mb code display warning that file size and file type not allowed. Problem is when I try to upload file bigger than 2mb. Than my code doesn't work. There is no displaying my warning that max allowed file size is 1mb. Database was updated but shouldn't be and header redirect me to success url. My code works fine on local server, but doesn't work on godaddy server when file is bigger than 2mb.

<?php

    if (isset($_FILES['image'], $_POST['news_id'])) {
    $image_name = $_FILES['image']['name'];
    $image_size = $_FILES['image']['size'];
    $image_temp = $_FILES['image']['tmp_name'];

    $allowed_ext = array('jpeg', 'jpg', 'png', 'gif');
    $image_ext = strtolower(end(explode('.', $image_name)));

    $news_id = $_POST['news_id'];
    $errors = array();

    if (empty($image_name) || empty($news_id)) {
        $errors[] = 'Oooop\'s! Something went wrong!';
    } else {

        if (in_array($image_ext, $allowed_ext) === false) {
            $errors[] = 'Allowed file type is "jpg, jpeg, png i gif"!';
        }

        if ($image_size > 1048576 ) {
            $errors[] = 'Max allowed file size is 1mb!';
        }

    }

    if (!empty($errors)) {
        foreach ($errors as $error) {
            echo output_errors($errors);
        }
    } else {
        $this->model->uploadImage($image_temp, $image_ext, $news_id);
        header('Location: ' . URL . 'admin_panel/add_images/success');
        exit();
    }
}
?>

Upvotes: 0

Views: 475

Answers (1)

Humba
Humba

Reputation: 128

Check your server php.ini configurations for upload_max_filesize and post_max_size They are limiting your upload max size, I think. You can try this code to check what is the php.ini limit:

echo ini_get('post_max_size');
echo ini_get('upload_max_filesize');

Upvotes: 1

Related Questions