Search code examples
phpapachedockercodeigniter-2docker-for-windows

Docker CodeIgniter 2.2.6 file upload not working


I'm trying to run CodeIgniter 2.2.6 application with LAMP stack setup with Docker on windows 10. Application is up and running and even database connectivity (with mariadb) is working fine. But, when I started to create a file upload functionality, it fails. Browser saying "172.18.0.3 took too long to respond."

Here is my docker-compose.yml file:-

version: '3'

services: 

  php-apache:
    build:
      context: ./docker/php-apache
    ports: 
      - 8081:80
    volumes: 
      - ./app:/var/www/html
    links: 
      - 'mariadb'

  mariadb: 
    build: 
      context: ./docker/mariadb
    ports:
      - 3306:3306
    volumes: 
      - mariadb:/var/lib/mysql
    environment: 
      MYSQL_ALLOW_EMPTY_PASSWORD: "no"
      MYSQL_ROOT_PASSWORD: "rootpwd"
      MYSQL_USER: 'testuser'
      MYSQL_PASSWORD: 'testpassword'
      MYSQL_DATABASE: 'testdb_codeigniter'

volumes: 
  mariadb:

Here is the Dockerfile for php-apache service:-

FROM php:5.6-apache
RUN docker-php-ext-install pdo pdo_mysql mysqli

# Override with custom opcache settings
COPY ./opcache.ini $PHP_INI_DIR/conf.d/

Here is the Dockerfile for mariadb service:-

FROM mariadb:latest

And here is my folder structure:-

Here is my folder structure:-

I have app, docker folders and docker-compose.yml file in my root. Inside the app folder I have the codeigniter files.

I have a php file for upload files (upload_form.php):-

<html>
    <head>
        <title>FIle Upload</title>
    </head>
    <body>
    <?= $error ?>
    <?= form_open_multipart('upload/upload_file') ?>
        <input type="file" name="userfile" size="20"><br/><br/>
        <input type="submit" value="Upload">
    </form>

    </body>
</html>

When I inspect this page in google Chrome, code will interpret as follows. (Please put attention on form action part.) :- enter image description here

After I choose a image file to upload and press upload button, page getting spin for several seconds and end up with following message:- enter image description here

I don't know what I did wrong and any kind of help is highly appreciated. Thanks.


Solution

  • Base URL should be absolute, including the protocol:

    $config['base_url'] = "http://somesite.com/";
    

    If using the URL helper, then base_url() will output the above string.

    If you don't include the base URL it usually takes the docker IP :)