これは私がPHPに精通していないために起こりそうですが、ここでは:私はFat-Free Frameworkを使ってプロジェクトを作成していますが、今は問題にぶつかりました。 /わかる。
これは$func
と$slug
両方が私が使用している機能を、することができ(receive($func=NULL,$overwrite=FALSE,$slug=TRUE)
メソッドを使用して、私は無脂肪のウェブ拡張子の取り扱いだファイルアップロードのためのコールバックメソッドの内部で何が起こっています以下の例を参照)。この拡張では、何らかの方法でファイルを検証するための引数として関数を使用し、ファイル名を変更するために関数を使用できます。
問題は、これらのメソッド内でグローバルな$ f3変数を使用できないことです。例えば。下のコードでは、maxFileSizeMb
変数に最大ファイルサイズを確認する変数を設定したいと考えていますが、$this->f3->get('maxFileSizeMb')
を直接呼び出すか、関数の前の変数に代入してコードを破棄します。
$this->f3->set('UPLOADS','uploads/'.$this->f3->get('tmpMediaPath').'/');
$this->f3->set('maxFileSizeMb', 2);
$this->f3->set('fileNameLenght', 30);
// Using f3 \Web extension
$overwrite = false; // set to true, to overwrite an existing file; Default: false
// $slug = true; // we'll generate a new filename
$web = \Web::instance();
$files = $web->receive(function($file,$formFieldName) {
// Check against the maximum allowed file size
if($file['size'] > (2 * 1024 * 1024)) // if bigger than 2 MB
// >>>^<<< using $this->f3->get('maxFileSizeMb'); breaks the code
return false; // this file is not valid, return false will skip moving it
return true; // allows the file to be moved from php tmp dir to your defined upload dir
},
$overwrite,
function($fileBaseName, $formFieldName){
$fileExtension = ".tmp"; // Determine the true image type and rename it later on
// ##TODO## check if value is truly unique against the database. Here or elsewhere?
$randomName = bin2hex(openssl_random_pseudo_bytes(30));
// >>> ^^ <<< using $this->f3->get('fileNameLenght'); breaks the code
return $randomName.$fileExtension;
}
);
ありがとうございます。