0

I have a small problem which would be a great help.

I have a function in laravel that captures certain data and at the end with $ file-> move ($ virtual_machine_address, document) it is saved in the created folder. This locally works wonders. The code is referenced fromsubir archivos en laravel (API)

public function uploadFile(Request $request){

    /*Initializing variables in input*/
    $input = $request->all();

    /*rutas de carpeta*/
    $ruta_server = DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR.'172.xx.xx.xxx'.DIRECTORY_SEPARATOR.'Prueba'.DIRECTORY_SEPARATOR.'DOCUMENTOS'.DIRECTORY_SEPARATOR;

    /*Enter if file exist*/
    if($request->hasFile('file')){

        /*Modification in the name and extension*/
        $file = $request->file('file');
        $filename = $file->getclientOriginalName();
        $filename = pathinfo($filename, PATHINFO_FILENAME);
        $name_file = str_replace(" ", "_", $filename);
        $extension = $file->getClientOriginalExtension();

        /*Redacción o revisión*/
        if($input['posicion'] == 1){
            $picture = 'Redaccion('.$input['version'].')' . '-' . $name_file . '.' . $extension;
        }else{
            $picture = 'Revision('.$input['version'].')' . '-' . $name_file . '.' . $extension;
        }

        /*official root*/
        $ruta_oficial = $ruta_server.$input['id_carpeta'].DIRECTORY_SEPARATOR;

        /*create and uploadfile*/
        $file->move($ruta_oficial, $picture);

        return response()->json([
            "ok" => true,
            "error" => false,
            "data" => $picture
        ]);
    }else{
        return response()->json([
            "ok" => false,
            "error" => true,
            "mensaje" => "Error Detectado"
        ]);
    } 
}

I created a container in docker that simulates the apache server configuration where the project will be uploaded and when testing my function with postman, it doesn't work. Sending the error:

Symfony\Component\HttpFoundation\File\Exception\FileException: Unable to create the "//172.xx.xx.xxx/Prueba/DOCUMENTOS/100-2021/" directory. in file /opt/data/vendor/symfony/http-foundation/File/File.php on line 125

Along with 38 # more bugs.

My project versions: Laravel: 8.48.0 PHP: 8.0.7 Docker container: FROM php:8.0.7-apache (Linux) File server (172.xx.xx.xxx): Windows Virtual Server

  • `172.xx.xx.xxx` is that the right ip for the one that does not work? – RiggsFolly Jul 05 '21 at 13:20
  • Are you able to reach the specified IP from the docker container? And have you checked the subject container networking in the docs (https://docs.docker.com/config/containers/container-networking/) ? – Andrew Larsen Jul 05 '21 at 13:24
  • @RiggsFolly That is the IP of the virtual machine where I have the space to save my project files. I did the test locally with that IP and it does save my documents. When I test on a docker image, this is where it fails. I put 'x' in the ip – Un Tal Rei Jul 05 '21 at 13:31
  • Well its not going to be that ip on the other machine is it – RiggsFolly Jul 05 '21 at 13:33
  • @AndrewLarsen The docker container I put it inside my backend and from the front-end I consult with the path http: // localhost: 5050 / api / All of my API database inquiries in Docker works good, but my function that saves my files (http: // localhost: 5050 / api / uploadFile) that give me problems. In localhost with XAMPP all my project work perfectlly. – Un Tal Rei Jul 05 '21 at 13:43
  • @RiggsFolly Yes, this isthe official IP, but without 'x'. I don't know if the problem is clear or if you need something else. – Un Tal Rei Jul 05 '21 at 13:48
  • 1
    From the docs: By default, when you create or run a container using docker create or docker run, it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container’s network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world. – Andrew Larsen Jul 05 '21 at 14:01
  • Or maybe this is more correct for your problem: https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach I know the OP is trying to connect to mysql. But the case is the same. You want to access something on the host machine (your localhost). – Andrew Larsen Jul 05 '21 at 14:02
  • @AndrewLarsen I ping 172.xx.xx.xxx and the container is seeing it. We did other tests and the docker is working fine. I think it should be clarified that the container is linux and the virtual machine with IP 172.xx.xx.xxx is windows – Un Tal Rei Jul 05 '21 at 14:43
  • https://www.howtogeek.com/176471/how-to-share-files-between-windows-and-linux/ check out the part that says "First, you’ll need the cifs-utils package in order to mount SMB shares. Just type the following command at the terminal:" – Andrew Larsen Jul 05 '21 at 15:55
  • @AndrewLarsen Nice article and is similar to what I wants to do, but I wanna want to do it with my php code. btw: I'm using windows pc, not linux. – Un Tal Rei Jul 05 '21 at 19:10
  • @UnTalRei as long as you are able to to it in your ssh shell, you can execute shell commands with php using the `exec` function. – Andrew Larsen Jul 06 '21 at 14:11
  • @AndrewLarsen Exec gave me some Error and my linux command knowledge isn't good. Now i'm trying with icewind – Un Tal Rei Jul 06 '21 at 21:48

1 Answers1

0

This is my DockerFile

FROM php:8.0.7-apache

RUN apt-get update

# 1. paauetes dev
RUN apt-get install -y \
    git \
    zip \
    samba \
    smbclient \
    curl \
    sudo \
    unzip \
    libpq-dev \
    libzip-dev \
    libicu-dev \
    libbz2-dev \
    libpng-dev \
    libjpeg-dev \
    libmcrypt-dev \
    libreadline-dev \
    libfreetype6-dev \
    libsmbclient-dev \
    g++ \
    libaio1 wget && apt-get clean autoclean && apt-get autoremove --yes &&  rm -rf /var/lib/{apt,dpkg,cache,log}/ 



# 2. dir apache
ENV APACHE_HOME /var/www/html


# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers

# 4. start with base php config, then add extensions
#RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

RUN docker-php-ext-install \
    gd\
    bz2 \
    intl \
    iconv \
    bcmath \
    opcache \
    calendar \
#    mbstring \
#    pdo_mysql \
    zip 
    

# 5. composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
 

# ORACLE oci 
RUN mkdir /opt/oracle \
    && cd /opt/oracle     
    
ADD http://git.xxx.xxx/bxxxx.xxxx/media/raw/master/IC/instantclient-basic-linux.x64-19.5.0.0.0dbru.zip /opt/oracle
ADD http://git.xxx.xxx/bxxxx.xxxx/media/raw/master/IC/instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip /opt/oracle

# Install Oracle Instantclient
RUN  unzip /opt/oracle/instantclient-basic-linux.x64-19.5.0.0.0dbru.zip -d /opt/oracle \
    && unzip /opt/oracle/instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip -d /opt/oracle \
  #  && ln -s /opt/oracle/instantclient_19_5/libclntsh.so.19.1 /opt/oracle/instantclient_19_5/libclntsh.so \
    && ln -s /opt/oracle/instantclient_19_5/libclntshcore.so.19.1 /opt/oracle/instantclient_19_5/libclntshcore.so \
  #  && ln -s /opt/oracle/instantclient_19_5/libocci.so.19.1 /opt/oracle/instantclient_19_5/libocci.so \
    && rm -rf /opt/oracle/*.zip
    
ENV LD_LIBRARY_PATH  /opt/oracle/instantclient_19_5:${LD_LIBRARY_PATH}
    
# Install Oracle extensions
RUN echo 'instantclient,/opt/oracle/instantclient_19_5/' | pecl install oci8-3.0.1 \ 
      && docker-php-ext-enable \
               oci8 \ 
       && docker-php-ext-configure pdo_oci --with-pdo-oci=instantclient,/opt/oracle/instantclient_19_5,19.5 \
       && docker-php-ext-install \
               pdo_oci 

RUN mkdir -p /opt/data/public && \
    rm -r /var/www/html && \
    ln -s /opt/data/public $APACHE_HOME


    
WORKDIR $APACHE_HOME