为了账号安全,请及时绑定邮箱和手机立即绑定

PHP move_uploaded_file()函数不起作用

PHP move_uploaded_file()函数不起作用

PHP
慕哥6287543 2021-04-27 13:46:56
获得了将产品添加到网上商店的表单。您最多可以上传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-php56Error log ^   
查看完整描述

2 回答

?
斯蒂芬大帝

TA贡献1827条经验 获得超8个赞

所以Cherrysoft所说的是正确的。它几乎可以肯定是权限问题,或者不符合您的想法。


我将利用这个机会来帮助您改进代码。您的示例可以简化,以便更轻松地添加10个以上的图像,并且更易于维护。这是您当前代码的更好替代方法:


if(isset($_POST['name'])){

    foreach($_FILES as $key => $file) {

        move_uploaded_file($file['tmp_name'],"../assets/img/carousel/{$file['name']}");

    }

}

这样,您的代码就不会那么重复了。有一些方法可以进一步改善这一点,但是我不想被迷住。


查看完整回答
反对 回复 2021-05-07
  • 2 回答
  • 0 关注
  • 262 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号