1. Go to this page and download the library: Download yii2-extensions/road-runner library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yii2-extensions / road-runner example snippets
declare(strict_types=1);
ttp\Application;
use yii2\extensions\roadrunner\RoadRunner;
// production default (change to 'true' for development)
defined('YII_DEBUG') or define('YII_DEBUG', false);
// production default (change to 'dev' for development)
defined('YII_ENV') or define('YII_ENV', 'prod');
declare(strict_types=1);
use yii2\extensions\debug\WorkerDebugModule;
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => WorkerDebugModule::class,
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
declare(strict_types=1);
use yii2\extensions\psrbridge\http\{Response, UploadedFile};
final class FileController extends \yii\web\Controller
{
public function actionUpload(): Response
{
$file = UploadedFile::getInstanceByName('avatar');
if ($file !== null && $file->error === UPLOAD_ERR_OK) {
// validate the file before saving; choose a server-controlled storage name
$file->saveAs('@runtime/uploads/' . bin2hex(random_bytes(16)) . '.bin');
}
return $this->asJson(['status' => 'uploaded']);
}
}