项目需要,做了一个nginx+php的简单文件上传功能。利用php上传文件,利用nginx的配置实现文件的下载。
nginx的配置
location ~ \.php$ {
#root /root/openressty/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/php/phpservice$fastcgi_script_name;
include fastcgi_params;
}
upload.php:
$method = $_SERVER['REQUEST_METHOD'];
if(strcasecmp($method, "POST") != 0){
echo "hello world!";
return;
}
$item = $_POST['item'];
$filePath = "/root/openressty/nginx/html/download/item.txt";
$file = fopen($filePath, "w+");
fwrite($file, $item);
fclose($file);
我想把上传上来的文件,保存到 filePath 这个路径下。但是使用时会报错,fopen(/root/openressty/nginx/html/download/item_db.txt): failed to open stream: Permission denied in
我已经创建了 item.txt 这个文件,并且改为777权限了。
用 file_exists($filePath),返回false。请问这该如何解决?
nginx的配置
location ~ \.php$ {
#root /root/openressty/nginx;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/php/phpservice$fastcgi_script_name;
include fastcgi_params;
}
upload.php:
$method = $_SERVER['REQUEST_METHOD'];
if(strcasecmp($method, "POST") != 0){
echo "hello world!";
return;
}
$item = $_POST['item'];
$filePath = "/root/openressty/nginx/html/download/item.txt";
$file = fopen($filePath, "w+");
fwrite($file, $item);
fclose($file);
我想把上传上来的文件,保存到 filePath 这个路径下。但是使用时会报错,fopen(/root/openressty/nginx/html/download/item_db.txt): failed to open stream: Permission denied in
我已经创建了 item.txt 这个文件,并且改为777权限了。
用 file_exists($filePath),返回false。请问这该如何解决?