【问题标题】:PhP : Impossible to move upload filePhP:无法移动上传文件
【发布时间】:2015-06-08 08:37:40
【问题描述】:

我无法让我的 move_uploaded_file() 不起作用,并且没有显示错误:/

这是我的表格:

<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>

和 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;

这是回声:

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

我不明白怎么了...我已经厌倦了这个上传的东西:(

感谢您的帮助:)

【问题讨论】:

  • 请看看我之前回答的一个问题。例如:stackoverflow.com/questions/22236035/…
  • 嗨,感谢您的帮助 :) 我在另一个页面上尝试了您的代码(以保持内容干净),但我仍然遇到同样的问题...没有错误,但也没有文件:/

标签: php file move


【解决方案1】:

尝试替换

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

通过

if(move_uploaded_file($_FILES['newPagePic']['tmp_name'], $destination_path.basename($_FILES['newPagePic']['name']));

【讨论】:

  • 谢谢,但还是一样:(
猜你喜欢
  • 1970-01-01
  • 2013-06-21
  • 2015-01-08
  • 2013-08-05
  • 1970-01-01
  • 2013-12-17
  • 1970-01-01
  • 2012-05-25
  • 2014-11-09
相关资源
最近更新 更多