java上传文件时404,404从apache网站上传文件后可从filemanager访问 . 文件夹和文件权限为644...

网站基于Yii PHP框架 . 当图像从网站(而不是ftp)上传到具有相同类型图像的文件夹(通常由http访问)时,此图像仅可在ftp中访问,并在http请求中导致404错误 .

文件夹和文件权限为755和644 .

换句话说,我有“bla / foo.jpg " and " bla / bla.png " which i can see by entering " http://my.url/bla/foo.jpg " and " http://my.url/bla/bla.png”或在FileZilla中使用相同的FTP地址 . 然后,我从index.html页面上传“girl.jpg”,它到达相同的/ bla文件夹 .

...我可以从FTP看到bla / girl.jpg,但不是来自“http://my.url/bla/girl.jpg” . 它具有与HTTP中看到的foo.jpg和bla.png相同的权限和相同的地址 .

文件正在从html表单上传,并在内置的Yii类的帮助下保存:

yii\web\UploadedFile;

yii\helpers\FileHelper;

yii\behaviors\TimestampBehavior;

yii\db\ActiveRecord;

public static function upload($file, $folder, $id = null, $title = null)

{

if ($file) {

$path = self::createFolder($folder) . '/' .

Yii::$app->security->generateRandomString() . '.' .

$file->extension;

if ($file->saveAs(Yii::getAlias('@root' . $path))) {

self::autorotateImage($file->extension, $path);

$fileStorage = self::findOne($id);

if ($fileStorage) {

$fileStorage->deleteFile();

} else {

$fileStorage = new FileStorage();

}

$fileStorage->path = $path;

$fileStorage->filename = $file->name;

$fileStorage->title = $title;

if ($fileStorage->validate() && $fileStorage->save()) {

return $fileStorage->id;

}

}

}

return null;

}

这是.htaccess内容:

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]

RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$

RewriteRule ^pages\/how\-it\-works$ "https\:\/\/mywebsite\.com\/pages\/how\-it\-works\/" [R=301,L]

RewriteEngine on

# If a directory or a file exists, use the request directly

# Otherwise forward the request to index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

RewriteCond %{HTTP_HOST} !^mywebsite.com$ [NC]

RewriteRule ^(.*)$ https://mywebsite.com/$1 [L,R=301]

#php_value upload_max_filesize 500M

#php_value post_max_size 550M

#php_value memory_limit 512M

#php_value max_input_time 500

#php_value max_execution_time 500

# Manual editing of this file may result in unexpected behavior.

php_flag display_errors Off

php_value max_execution_time 30

php_value max_input_time 60

php_value max_input_vars 1000

php_value memory_limit 128M

php_value post_max_size 8M

php_value session.gc_maxlifetime 1440

php_value session.save_path "/var/cpanel/php/sessions/ea-php70"

php_value upload_max_filesize 2M

php_flag zlib.output_compression Off

# END cPanel-generated php ini directives, do not edit

# php -- BEGIN cPanel-generated handler, do not edit

# Set the “ea-php72” package as the default “PHP” programming language.

AddType application/x-httpd-ea-php72 .php .php7 .phtml

# php -- END cPanel-generated handler, do not edit

UPD:

尝试了Alon Eitan对这种机制的建议,但问题保持不变:

if ($fileStorage->validate() && $fileStorage->save()) {

$oldFolder = dirname(Yii::getAlias('@root' . $path));

$newFolder = $oldFolder . "_new";

mkdir($newFolder, 0755);

self::xcopy($oldFolder, $newFolder);

self::delete_dir($oldFolder);

rename($newFolder, $oldFolder);

return $fileStorage->id;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值