0

i can't make my move_uploaded_file() doesn't work and there's no error displaying :/

Here's my form :

<form enctype="multipart/form-data" name="addNewCarnet" action="carnet.php" method="post">
                            <div><br>
                                <label for="carnetTitle">Titre de la page :</label><input type="text" name="carnetTitle" value="" /><br>
                                <br>
                                <label for="pageText">Texte :</label><br><br>
                                <textarea class="ckeditor" type="textarea" name="pageText"></textarea><br>
                                <br>
                                <div class="input-file-container">
                                    <input class="input-file" name="newPagePic" type="file">
                                    <label for="newPage" class="input-file-trigger labelImage" tabindex="0">Image</label>
                                </div>
                                <p class="file-return"></p>
                                <br>
                                <br>
                                <input type="submit" name="submitNewPage" value="Envoyer"><br>
                            </div>
                        </form>

and the PhP :

if ($_FILES['newPagePic']['error'] > 0) $erreur = "Erreur lors du transfert"; // Vérifier l'upload
            else echo "transfert réussi";

            var_dump($_FILES);

            $extensions_valides = array( 'jpg' , 'jpeg' , 'gif' , 'png' ); // Vérification extension
            $extension_upload = strtolower(  substr(  strrchr($_FILES['newPagePic']['name'], '.')  ,1)  );
            if(!(in_array($extension_upload,$extensions_valides))) echo 'Extension incorrecte !';

            //Créer un dossier 'images/users/"id_user"'
            $destination_path = getcwd().DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'users'.DIRECTORY_SEPARATOR.$_SESSION["user_id"].DIRECTORY_SEPARATOR;
            if (!(is_dir($destination_path))) mkdir($destination_path, 0777, true);

            $nom = $_FILES['newPagePic']['name'];
            if(is_writable($destination_path))
            {
                echo "ok<br>";
            }
            else
            {
                echo "no writable<br>";
            }
            if(move_uploaded_file($_FILES['newPagePic']['tmp_name'], $destination_path.$nom))
              echo 'Transfert réussi';
            else
              echo $_FILES['newPagePic']['error'] ."<br>". $_FILES['newPagePic']['tmp_name'] ."<br>". $destination_path.$nom;

Here's the echoing :

https://i.stack.imgur.com/OlLQl.png

I don't get what's wrong ... I'm getting tired of this uploaded thing :(

Thank you for your help :)

BenG
  • 14,826
  • 5
  • 45
  • 60
Thyronia
  • 1
  • 1
  • please take a look at one of the earlier questions I answered about this. Forexample: http://stackoverflow.com/questions/22236035/insert-picture-into-database-using-php/22236798#22236798 – SuperDJ Jun 08 '15 at 08:41
  • Hi, thanks for your help :) I tried your code on another page (to keep something clean) and i still have the same problem ... No error but no file neither :/ – Thyronia Jun 08 '15 at 08:51

1 Answers1

0

Try replacing

if(move_uploaded_file($_FILES['newPagePic']['tmp_name'], $destination_path.$nom))

by

if(move_uploaded_file($_FILES['newPagePic']['tmp_name'], $destination_path.basename($_FILES['newPagePic']['name']));
Antoine Delia
  • 1,728
  • 5
  • 26
  • 42