如何在上传之前获取文件值?这是示例代码。
SpringExtensionImpl springExtensionImpl;
actorSystem.actorOf(springExtensionImpl.create(Test.class, account, order));
这是控制器。
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?> <!-- Error Message will show up here -->
<?php echo form_open_multipart('upload_controller/do_upload');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>
</body>
</html>
我尝试显示“userfile”值,但它总是显示null。我怎样才能显示这个价值。
答案 0 :(得分:1)
如果您需要获取文件名......
<?php echo "<input type='file' name='userfile' size='20' onchange='changeEventHandler(event);' />"; ?>
<script>
function changeEventHandler(event){
alert(event.target.value);
}
</script>
...
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png'; //if your file is image
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$data = $this->upload->data()
echo $data['file_name'];
...
}
...或使用PHP
$name_file = $_FILES['userfile']['name'];