我正在用Codeigniter 4上传文件。我希望页面在加载后刷新,但我的代码不起作用。这是我使用的控制器。在底部我有重定向的代码,但这个代码不起作用。
<?php namespace App\Controllers;
use App\Models\Hizmetmodels;
use App\Models\Dosyamodels;
class Dosyacontroller extends BaseController
{
protected $helpers = ['form' ,'url'];
protected $Dosyamodels;
public function index($sap = null)
{
$Hizmetmodels= new Hizmetmodels();
$data['hizmetsat'] = $Hizmetmodels->where('sap', $sap)->first();
$Dosyamodels= new Dosyamodels();
$where = "sap='$sap'";
$data['dosya'] = $Dosyamodels->orderBy('id', 'ASC')->where($where)->findAll();
return view('Admin/Dosyalar/index', $data);
}
public function form()
{
$sap = $this->request->getPost('sap');
$Dosyamodels= new Dosyamodels();
helper(['text','inflector']);
$file = $this->request->getFile('file');
$size = $file->getSize();
$kilobytes = $file->getSizeByUnit('kb');
$path = 'public/uploads';
$name = convert_accented_characters(underscore($file->getName()));
$newname = "$sap-$name";
$file->move(ROOTPATH . $path, $newname);
$ext = $file->getClientExtension();
$data = [
'adi' => $newname,
'yol' => $path . '/' . $name,
'sap' => $sap,
'boyut' => $kilobytes,
'uzt' => $ext,
];
$save = $Dosyamodels->insert($data);
return redirect()->to('/Dosyalar/index/'. $sap)->with('success', 'Tebrikler! <br> Dosyalar başarı ile yüklendi.');
}
}
3条答案
按热度按时间inn6fuwd1#
问题可能与您尝试重定向到的重定向URL有关。在本例中,URL为/Dosyalar/index/'.$sap,缺少基本URL。要解决此问题,您可以在重定向URL中使用基本URL,如下所示:
bn31dyow2#
尝试将
this.on('queuecomplete', function (file) { location.reload(); });
更改为this.on('success', function (file, responseText) { location.reload(); });
nkoocmlb3#
与dropzone的文件被上传到正确的文件夹。保存到数据库。没有问题,到目前为止。唯一的问题是我不能刷新页面,无论我做什么后,它loads.here是我的java脚本代码: