GeorgesLemy's avatar

move_uploaded_file()

Hello, I have an application, an API and a bdd on a server present in an Active Directory Developing in php (laravel) I used the function move_uploaded_file() to import files to the server from the stations present in my Active Directory and it works. Moreover the Active Directory allows a remote ip for permit an access to the server to be able to use the application and everything works except file import (which returns absolutely nothing) I am completely lost ....

0 likes
6 replies
Snapey's avatar

perhaps you would care to explain what laravel issue you have and show some code. Active Directory is completely irrelevant.

GeorgesLemy's avatar

I make my import with that:

  public static function importOne(){



       $dossier = env('FILEBASEByCopie');
        // $fichier = basename($_FILES["import"]['name']);
        $newName = $_POST['newName'];
        $taille_maxi = 1000000000;
        $taille = filesize($_FILES['import']['tmp_name']);
        $extensions = array('.png','.jpg', '.jpeg');
        $extension1 = strrchr($_FILES['import']['name'], '.');
        $extensionFinal = str_replace('.', '',$extension1 );
        //Début des vérifications de sécurité...
        if(!in_array($extension1, $extensions)) //Si l'extension n'est pas dans le tableau
        {
             $erreur = 'Vous devez uploader un fichier de type png, jpg ou jpeg';
        }
        if($taille>$taille_maxi)
        {
             $erreur = 'Le fichier est trop gros...';
        }
        if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload
        {
             //On formate le nom du fichier ici...

             if(move_uploaded_file($_FILES['import']['tmp_name'], $dossier . $newName)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
             {

                  echo 'Upload effectué avec succcès';
                  echo 'console.log('. json_encode( $dossier ) .')';







                  $params=[$_POST['codeEan'],$newName,$_POST['numFichier'],$extensionFinal];
                  $url = env('API').'/api/produit/add/photo';
                  return Curl::post($params,$url);


             }
             else //Sinon (la fonction renvoie FALSE).
             {
                  echo 'Echec de l\'upload !';
             }
        }
        else
        {
             echo $erreur;
        }

  }

but i don't have any error message, my var_dump() or my log return the good file name and the good dir path. My if(move_uploaded_file($_FILES['import']['tmp_name'], $dossier . $newName)) return TRUE but I don't have any file move

Snapey's avatar

I suggest you review some of the MANY tutorials for file upload that are Laravel specific

You could use Laravel's validation for half of this code

You could also use the uploaded file object to simplify a lot of the rest of the code.

GeorgesLemy's avatar

Thank you Snapey I found the problem and now it works !!

Please or to participate in this conversation.