该网站基于Yii PHP框架。当图像从网站(非ftp)上载到具有相同类型图像(通常通过http访问)的文件夹时,此图像仅在ftp中可访问,并在http请求中导致404错误。
文件夹和文件权限为755&644
bla/bla.png
http://my.url/bla/foo.jpg
“和”
http://my.url/bla/bla.png
“或在中使用相同的FTP地址
菲利齐拉
. 然后,我上传“
“从
index.html
一页,它就到了同一页
/布拉
...
我可以从FTP中看到bla/girl.jpg,但不能从“
http://my.url/bla/girl.jpg
". 它具有与相同的权限和地址
和
bla.png
我从HTTP中看到。
文件从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;
}
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.
<IfModule php7_module>
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
</IfModule>
# 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.
<IfModule mime_module>
AddType application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
UPD:
用这个机制尝试了艾坦的建议,但问题依然存在:
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;
}