doumei1926 2019-04-13 22:23
浏览 48

表单上传到/ tmp / phpHQ6U5X而不是新设置/ var / www / html / upload_tmp

I am trying to upload files to my server through a CRUD. I am having an issue moving the uploaded file to its new directory which exists.

I am receiving this warning..

Warning: move_uploaded_file(../images/me.png): failed to open stream: Permission denied in /var/www/html/admin/addpicture.php
Warning: move_uploaded_file(): Unable to move '/tmp/phpHQ6U5X' to '../images/me.png'

Realizing this might be a permission issue with /tmp, I decided to change the temporary upload folder.

I set a temporary upload folder in the php.ini file I found listed in phpinfo()

Configuration File (php.ini) Path   /etc/php/7.0/apache2

I restarted my server using

sudo systemctl restart apache2

I checked to make sure my changes were set with phpinfo() again

upload_tmp_dir  /var/www/html/upload_tmp

Also, I checked to see if my basedir is set

open_basedir    no value

I tried to upload the file again

Warning: move_uploaded_file(): Unable to move '/tmp/phpHQ6U5X' to '../images/me.png'

I am including code for completeness but I can confirm that this code works for me on localhost and other servers I have worked on.

PHP

if(isset($_FILES) & !empty($_FILES)){
  $name = $_FILES['pictureimage']['name'];
  $size = $_FILES['pictureimage']['size'];
  $type = $_FILES['pictureimage']['type'];
  $tmp_name = $_FILES['pictureimage']['tmp_name'];
  $max_size = 10000000;
  $extension = substr($name, strpos($name, '.') + 1);

  if(isset($name) && !empty($name)){
    if($size<=$max_size){
      $location = '../images/';
      $filepath = $location.$name;
      if(move_uploaded_file($tmp_name, $filepath)){

HTML

<input type="file" name="pictureimage" id="pictureimage">

What am I missing? Why would the form continue to upload to /tmp instead of the upload_tmp_dir that I set?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?