46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
namespace backend\controllers;
|
|
|
|
use yii\rest\ActiveController;
|
|
use yii\rest\Controller;
|
|
|
|
class UploadController extends Controller
|
|
{
|
|
|
|
|
|
|
|
|
|
// public function verbs()
|
|
// {
|
|
// $verbs = [];
|
|
// $verbs[ "upload" ] = ['POST' ];
|
|
// return $verbs;
|
|
// }
|
|
|
|
public function actionUpload()
|
|
{
|
|
$postdata = fopen( $_FILES[ 'data' ][ 'tmp_name' ], "r" );
|
|
// /* Get file extension */
|
|
$extension = substr( $_FILES[ 'data' ][ 'name' ], strrpos( $_FILES[ 'data' ][ 'name' ], '.' ) );
|
|
|
|
// /* Generate unique name */
|
|
$filename = \Yii::getAlias('@frontend') ."/web/profile/" . uniqid() . $extension;
|
|
echo $filename;
|
|
|
|
// /* Open a file for writing */
|
|
$fp = fopen( $filename, "w" );
|
|
|
|
/* Read the data 1 KB at a time
|
|
and write to the file */
|
|
while( $data = fread( $postdata, 1024 ) )
|
|
fwrite( $fp, $data );
|
|
|
|
/* Close the streams */
|
|
fclose( $fp );
|
|
fclose( $postdata );
|
|
|
|
/* the result object that is sent to client*/
|
|
|
|
echo "ok";
|
|
}
|
|
} |