我已经编写了关于图像上传的代码,但它在byexost服务器中无效。我在服务器的根位置下创建了"uploads/products"
目录,该文件夹也是可写的,但它仍然无法正常工作。请帮忙。
我打开了应用程序的错误日志记录。如果我访问"application/logs"
目录的日志文件,则会显示以下错误。
错误 - 2018-03-25 00:47:08 - > 404找不到页面:/ index
错误 - 2018-03-25 00:58:24 - >上传路径似乎不是 有效的。
byexost服务器中图片上传目录的图片
我的产品控制器代码。
if(isset($_FILES['productimage']['name'])){
$filename = $_FILES['productimage']['name'];
$config['file_name'] = $filename;
$config['upload_path'] = realpath(FCPATH.'uploads/products/');
$config['allowed_types'] = 'jpg|jpeg|png';
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = TRUE;
$config['min_width'] = 360;
$config['min_height'] = 360;
$config['max_width'] = 360;
$config['max_height'] = 360;
$this->upload->initialize($config);
if($this->upload->do_upload('productimage')){
$uploadeddata = $this->upload->data();
$data['image'] = $uploadeddata['file_name'];
}else{
$this->session->set_flashdata('error', $this->upload->display_errors());
$result = array("status"=>false, "message"=>$this->upload->display_errors());
}
}
答案 0 :(得分:2)
检查upload_tmp_dir权限(PHP使用的权限)。原生文件上传分为两步:上传到tmp目录并移动到你想要的任何内容。
另请确保您尝试上传符合upload limit的文件。
答案 1 :(得分:1)
创建档案upload_form.php
&放置它application/views/
文件夹:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
创建upload_success.php
并将其application/views/
文件夹:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
将其命名为upload.php
并将其放在application/controllers/
文件夹中:
class Upload extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index(){
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload(){
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['remove_spaces'] = TRUE;
$config['encrypt_name'] = TRUE;
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')){
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
代码点火器的REST过程与通常相同。在/htdocs/codeigniter/
文件夹中创建上传文件夹。如果您使用的是Windows,请在/var/www/html/codeigniter/
文件夹中创建一个上传文件夹。
输出应该如下所示。
Your file was successfully uploaded!
file_name: 6cedb4d846cade717196c96c155537fd.png
file_type: image/png
file_path: /var/www/html/ci/upload/
full_path: /var/www/html/ci/upload/6cedb4d846cade717196c96c155537fd.png
raw_name: 6cedb4d846cade717196c96c155537fd
orig_name: download.png
client_name: download.png
file_ext: .png
file_size: 4.76
is_image: 1
image_width: 126
image_height: 126
image_type: png
image_size_str: width="126" height="126"
答案 2 :(得分:1)
除了完全糟糕的配置外,还有两个可能的问题,我在这里看不到:
树中的一个文件夹是不可读的,即'uploads'和'products'目录都必须是可读的,当然也是可写的。
其他一些系统错误导致目录访问失败,例如:没有足够的磁盘空间或selinux权限。
答案 3 :(得分:1)
您可以更改服务器上传目录777权限,这可以解决您的问题
答案 4 :(得分:1)
尝试使用以下
更新.htaccessSELECT ( (SELECT COUNT(*) FROM scheme.student) +
(SELECT COUNT(*) FROM scheme.employer)
) AS 'Column' ;