php cannot upload file (777+group:apache+ selinux disabled)

WBOY
Release: 2023-03-01 21:38:01
Original
1379 people have browsed it

As the title says, centos7
upload_temp_dir=/tmp(777)
$_SERVER['DOCUMENT_ROOT']. '/adpic'(777)

<code><?php

// 检测文件
if (!isset($_FILES['file']) || !is_uploaded_file($_FILES['file']['tmp_name']))
    exit('错误,没有找到文件' . json_encode(var_dump($_FILES)));

if ($_FILES['file']['error'] > 0)
    exit('错误,文件错误');

if ($_FILES['file']['size'] < 0)
    exit('错误,文件大小不明');

//switch (getimagesize($_FILES['file']['tmp_name'])[2]) {
//    case 1:
//        $ext = 'gif';
//        break;
//    case 2:
//        $ext = 'jpg';
//        break;
//    case 4:
//        $ext = 'jpeg';
//        break;
//    case 3:
//        $ext = 'png';
//        break;
//    default:
//        die('仅允许上传 png gif jpg 格式的图片' . var_dump($_FILES));
//        break;
//}

// 文件路径 文件名

$time = time();
$imgName = $time . mt_rand(10000, 99999);
$savePath =$_SERVER['DOCUMENT_ROOT']. '/adpic';
// 创建文件夹
// 移动文件
if (!move_uploaded_file($_FILES['file']['tmp_name'], $savePath . '/' . $imgName . '.' . $ext))
    exit('错误,文件移动失败'.error_reporting(E_ALL));

// 返回文件地址
exit("/adpic/" . $imgName . '.' . $ext);</code>
Copy after login
Copy after login

The first question is, getimagesize($_FILES'file') is false. What is the situation?
Shouldn’t the normal one be available?
Then the error message is 22527.
The problem description is roughly like this. If more information is needed, I will update it immediately. Thanks for the answer.

Reply content:

As the title says, centos7
upload_temp_dir=/tmp(777)
$_SERVER['DOCUMENT_ROOT']. '/adpic'(777)

<code><?php

// 检测文件
if (!isset($_FILES['file']) || !is_uploaded_file($_FILES['file']['tmp_name']))
    exit('错误,没有找到文件' . json_encode(var_dump($_FILES)));

if ($_FILES['file']['error'] > 0)
    exit('错误,文件错误');

if ($_FILES['file']['size'] < 0)
    exit('错误,文件大小不明');

//switch (getimagesize($_FILES['file']['tmp_name'])[2]) {
//    case 1:
//        $ext = 'gif';
//        break;
//    case 2:
//        $ext = 'jpg';
//        break;
//    case 4:
//        $ext = 'jpeg';
//        break;
//    case 3:
//        $ext = 'png';
//        break;
//    default:
//        die('仅允许上传 png gif jpg 格式的图片' . var_dump($_FILES));
//        break;
//}

// 文件路径 文件名

$time = time();
$imgName = $time . mt_rand(10000, 99999);
$savePath =$_SERVER['DOCUMENT_ROOT']. '/adpic';
// 创建文件夹
// 移动文件
if (!move_uploaded_file($_FILES['file']['tmp_name'], $savePath . '/' . $imgName . '.' . $ext))
    exit('错误,文件移动失败'.error_reporting(E_ALL));

// 返回文件地址
exit("/adpic/" . $imgName . '.' . $ext);</code>
Copy after login
Copy after login

The first question is, getimagesize($_FILES'file') is false. What is the situation?
Shouldn’t the normal one be available?
Then the error message is 22527.
The problem description is roughly like this. If more information is needed, I will update it immediately. Thank you for your answer.

Solved. After comparing php.ini, we found that it was due to the value of open_basedir. After leaving it empty, it returned to normal.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template