PHP $_FILES 上传文件,在Windows下正常,但在Ubuntu下无法上传文件
以下源码在Windows Apache下可正常上传文件,但在Ubuntu Linux下不会报错,但上传文件无法到指定目录。
请教各位如何解决。
谢谢!
$ErrorMessage=null;
$Message=null;
if(!empty($_FILES['fileField']['name'])){
if($_FILES['fileField']['error']>0){
$ErrorMessage='Error: '.$_FILES['fileField']['error'];
}else{
if (is_uploaded_file($_FILES['fileField']['tmp_name'])){
//转移文件
move_uploaded_file($_FILES['fileField']['tmp_name'],
'/var/www' .'/'. $_FILES['fileField']['name']);
$Message='上传成功!';
}else{
$ErrorMessage='Error: '.'上传失败!';
}
}
}
?>
回复讨论(解决方案)
估计是权限问题吧 上传目录改成777测试一下
windows 是单用户操作系统,很少会遇到权限问题。即使是在服务器上,由于有微软强大的团队,出现权限问题也是极少的
linux 是多用户操作系统(即便只有你一个人在用),所以权限问题无处不在。开源项目尚未技术支撑较弱,至今也没有出现简洁快捷的工具
move_uploaded_file 会判断是否为上传文件, is_uploaded_file 多次一举
而 move_uploaded_file 遇到目录不存在、不可写、空间不足的时候会返回错误状态
而你不加判别就 $Message='上传成功!'; 是不妥当的
在程序最?加上
ini_set('display_errors','on');
error_reporting(E_ALL);
?行后就知道是什??了,一般都是文件??限??
可在linux?端使用命令
?置文件??用?是www-data
chgrp www-data folder
然後?置??限
chmod g+rw folder
打开错误提示看看
'/var/www' .'/'. $_FILES['fileField']['name']
贴出目录文件权限
多谢各位,确实是权限问题,修改后就好了。
谢谢

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

Solving the problem of slow Photoshop startup requires a multi-pronged approach, including: upgrading hardware (memory, solid-state drive, CPU); uninstalling outdated or incompatible plug-ins; cleaning up system garbage and excessive background programs regularly; closing irrelevant programs with caution; avoiding opening a large number of files during startup.

Multithreading is an important technology in computer programming and is used to improve program execution efficiency. In the C language, there are many ways to implement multithreading, including thread libraries, POSIX threads, and Windows API.

How to implement Windows-like in front-end development...
