猿问

PHP move_uploaded_file()函数不起作用

获得了将产品添加到网上商店的表单。您最多可以上传10张图片,最少可以上传1张图片。即使将文件名完美地插入到MySQL数据库中,文件也不会移动到正确的文件夹中。


我正在使用共享的Web主机PHP 5.2,该文件具有写权限。已经与虚拟主机进行过交谈,这不是权限问题。


<form action="" method="post" enctype="multipart/form-data">

                  <div class="form-group">

                    <label for="img1"><b>Image 1</b></label>

                    <input required type="file" class="form-control" name="img1" placeholder="Image 1 (name of the first image, upload it as instructed)">

                  </div>

                  <div class="form-group">

                    <label for="img2"><b>Image 2</b></label>

                    <input type="file" class="form-control" name="img2" placeholder="Image 2 (name of the first image, upload it as instructed)">

                  </div>

                  <div class="form-group">

                    <label for="img3"><b>Image 3</b></label>

                    <input type="file" class="form-control" name="img3" placeholder="Image 3 (name of the first image, upload it as instructed)">

                  </div>

                  <div class="form-group">

                    <label for="img4"><b>Image 4</b></label>

                    <input type="file" class="form-control" name="img4" placeholder="Image 4 (name of the first image, upload it as instructed)">

                  </div>

                  <div class="form-group">

                    <label for="img5"><b>Image 5</b></label>

                    <input type="file" class="form-control" name="img5" placeholder="Image 5 (name of the first image, upload it as instructed)">

                  </div>

     

获取文件名称并将其移动到正确文件夹的部分。


这些文件没有移到旋转木马文件夹,而是根本没有移到任何地方:


[Thu Apr 18 18:53:34.249395 2019] 

[cgi:error] [pid 13994] 

[client 172.69.130.13:32306] AH01215: PHP Warning:  move_uploaded_file(): 

Unable to move '/tmp/phpOjN6YW' to '../assets/img/carousel/download (2).jpg' 

in /home/seniorte/public_html/admin/add.php 

on line 338: /usr/local/cpanel/cgi-sys/ea-php56

Error log ^

   

慕哥6287543
浏览 263回答 2
2回答

斯蒂芬大帝

所以Cherrysoft所说的是正确的。它几乎可以肯定是权限问题,或者不符合您的想法。我将利用这个机会来帮助您改进代码。您的示例可以简化,以便更轻松地添加10个以上的图像,并且更易于维护。这是您当前代码的更好替代方法:if(isset($_POST['name'])){&nbsp; &nbsp; foreach($_FILES as $key => $file) {&nbsp; &nbsp; &nbsp; &nbsp; move_uploaded_file($file['tmp_name'],"../assets/img/carousel/{$file['name']}");&nbsp; &nbsp; }}这样,您的代码就不会那么重复了。有一些方法可以进一步改善这一点,但是我不想被迷住。
随时随地看视频慕课网APP
我要回答