简体   繁体   English

使用codeigniter的文件上传错误

[英]file upload error using codeigniter

I am tryin to upload file in mysql database using php with codeigniter framework. 我正在尝试使用带有Codeigniter框架的php在mysql数据库中上传文件。 Following my code. 按照我的代码。 Its just saving first name of file in database but actual file in not storing at the given path. 它只是将文件的名字保存在数据库中,而实际文件则不保存在给定的路径中。

My code is - 我的代码是-

move_uploaded_file($_FILES["userfile"]["tmp_name"] , "uploads/diagnosis_report/".$_FILES["userfile"]["name"]);          

$data['file_name'] = $_POST["userfile"]["name"];

I believe: 我相信:

$data['file_name'] = $_POST["userfile"]["name"];

Should be: 应该:

$data['file_name'] = $_FILES["userfile"]["name"];
// ---------------------^

$upload_path $_POST["userfile"]["name"] is just the file name. $ upload_path $_POST["userfile"]["name"]只是文件名。 If you want to save it with the path you need to do something like this: 如果要使用路径保存它,则需要执行以下操作:

// For relative path
$data['file_name'] = "uploads/diagnosis_report/".$_FILES["userfile"]["name"];

// For absolute path
$data['file_name'] = dirname(__FILE__)."/uploads/diagnosis_report/".$_FILES["userfile"]["name"];

Honestly what I would do is set an upload path variable first like so: 老实说,我会先设置一个上传路径变量,如下所示:

$upload_path = dirname(__FILE__)."/uploads/diagnosis_report/";

Then you can use it over and over again like so: 然后,您可以像这样反复使用它:

move_uploaded_file($_FILES["userfile"]["tmp_name"] , $upload_path.$_FILES["userfile"]["name"]);          

$data['file_name'] = $upload_path.$_FILES["userfile"]["name"];

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM