上传文件苗条框架不同的目录

时间:2019-01-16 05:32:37

标签: file-upload frameworks slim

我将文件上传到本地主机中的不同服务器时遇到问题。在此代码成功中,但是我想要像这样的目录$ directory ='http://localhost/jurnal/dataJurnal/journals/2/articles/';

$ app-> post('/ api / uploadArsip',函数(Request $ request,Response $ response){

$directory = 'C:\xampp\htdocs\jurnal\dataJurnal\journals\2\articles';
//mkdir("hallo\hai",0777,true);
$uploadedFiles = $request->getUploadedFiles();

// handle single input with single file upload
$uploadedFile = $uploadedFiles['fileArsip'];
print_r($uploadedFiles['fileArsip']);
$basename = pathinfo($uploadedFile->getClientFilename(), PATHINFO_FILENAME);
print_r($uploadedFile);

if ($uploadedFile->getError() === UPLOAD_ERR_OK) {
    $extension = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);

    $filename = sprintf('%s.%0.8s', $basename, $extension);

    $uploadedFile->moveTo($directory . DIRECTORY_SEPARATOR . $filename);
    $response->write('uploaded ' . $filename . '<br/>');
}else{
$response->write('gagal <br/>');
}

});

0 个答案:

没有答案