我在view文件夹中有一个company_add_product.php,这是代码:
<?php
echo form_open_multipart('home/company_do_upload/', 'onsubmit="FormSubmit(this);"');
$disabled = array(
'class' => 'form-control',
'maxlength' => '100',
'style' => 'width:100%',
);
echo '<div class="form-group">';
echo '<div class="col-md-6">';
echo '<label for="name"> ناو: </label>';
echo form_input('name', set_value('name'), $disabled);
echo '</div>';
$class = array(
'class' => 'form-control',
'maxlength' => '100',
'style' => 'width:100%',
);
echo '<div class="col-md-6">';
echo '<label for="manufacturer"> ناوی کۆمپانیای بەرهەمهێن: </label>';
echo '<input type="hidden" name="manufacturer" />';
echo '<select name="manufacturer_ddl" class="form-control" onchange="DropDownChanged(this);">';
foreach ($manufacturers_name as $row) {
echo '<option value="'.$row['manufacturers_id'].'">'.$row['manufacturers_name'].'</option>';
}
echo '<option value="">تیای نییە..</option>';
echo '</select>';
echo '<input type="text" name="manufacturer_txt" style="display: none;" class="form-control" placeholder="تکایە ناوی کۆمپانیاکە بنوسە" />';
echo '</div>';
echo '</div>';
echo '<div class="form-group">';
echo '<div class="col-md-6">';
echo '<label for="model"> مۆدێل: </label>';
echo form_input('model', set_value('model'), $class);
echo '</div>';
echo '<div class="col-md-6">';
echo '<label for="category"> جۆری شمەک: </label>';
echo '<select name="category" class="form-control">';
foreach ($categories_name as $row) {
echo '<option value="'.$row['categories_id'].'">'.$row['categories_name'].'</option>';
}
echo '</select>';
echo '</div>';
echo '</div>';
echo '<div class="form-group">';
echo '<div class="col-md-6">';
echo '<label for="price"> نرخی فرۆشتن: </label>';
echo form_input('price', set_value('price'), $class);
echo '</div>';
echo '<div class="col-md-6">';
echo '<label for="stock"> دانە بۆ فرۆشتن: </label>';
echo form_input('stock', set_value('stock'), $class);
echo '</div>';
echo '</div>';
echo '<div class="form-group">';
echo '<label for="used"> بەکارهاتووە: </label>';
echo form_checkbox('used', 'بەڵێ');
echo '</div>';
$textarea = array(
'class' => 'form-control',
'rows' => '5',
'cols' => '10',
'style' => 'width:48%',
'name' => 'description',
);
echo '<div class="form-group">';
echo '<label for="description"> زانیاری زیاتر: </label>';
echo form_textarea($textarea, set_value('description'));
echo '</div>';
$img = array(
'class' => 'form-control',
'maxlength' => '100',
'style' => 'width:25%',
'name' => 'img',
);
echo '<div class="form-group">';
echo '<label for="img"> وێنەی سەرەکی: </label>';
echo form_upload('uploadedimages[0]','','multiple');
echo '</div>';
echo '<div class="form-group">';
echo '<label for="img"> وێنەی سەرەکی: </label>';
echo form_upload('uploadedimages[1]','','multiple');
echo '</div>';
echo '<div class="form-group">';
echo '<label for="img"> وێنەی سەرەکی: </label>';
echo form_upload('uploadedimages[2]','','multiple');
echo '</div>';
$submit_class = array(
'class' => 'btn btn-primary',
);
echo '<input type="submit" value="upload" />';
echo form_close();
?>
这是上传产品的控制器中的功能:
function company_do_upload()
{
if($this->session->userdata('is_logged_in') || $this->session->userdata('admin_logged_in')){
$user_id = $this->session->userdata('user_id');
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
if (is_numeric($this->input->post('manufacturer'))) {
//form validation
$this->form_validation->set_rules('name', 'ناوی کاڵا', 'required');
$this->form_validation->set_rules('model', 'مۆدێل');
$this->form_validation->set_rules('category', 'جۆری کاڵا', 'required');
$this->form_validation->set_rules('price', 'نرخی کاڵا', 'required|numeric');
$this->form_validation->set_rules('stock', 'دانە', 'required');
$this->form_validation->set_rules('description', 'ڕونکردنەوە');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$config['upload_path'] = './uploads/products/temp';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1200';
$config['max_width'] = '720';
$config['max_height'] = '576';
$config['multi'] = 'ignore';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('uploadedimages'))
{
$error = array('error' => $this->upload->display_errors());
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$error['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
if (!$data['upload_data'][1]['full_path']) {
$data['upload_data'][1]['full_path'] = NULL;
}
if (!$data['upload_data'][2]['full_path']) {
$data['upload_data'][2]['full_path'] = NULL;
}
$data_to_store = array(
'name' => $this->input->post('name'),
'manufacturers_id' => $this->input->post('manufacturer'),
'model' => $this->input->post('model'),
'categories_id' => $this->input->post('category'),
'sell_price' => $this->input->post('price'),
'stock' => $this->input->post('stock'),
'used' => $this->input->post('used'),
'description' => $this->input->post('description'),
'img' => substr($config['upload_path'], 1).'/'.$data['upload_data'][0]['file_name'],
'img1' => substr($config['upload_path'], 1).'/'.$data['upload_data'][1]['file_name'],
'img2' => substr($config['upload_path'], 1).'/'.$data['upload_data'][2]['file_name'],
'product_date' => date('Y-m-d H:i:s'),
'company_id' => $this->session->userdata('company_id'),
'uploader_ip' => $this->input->ip_address(),
);
//if the insert has returned true then we show the flash message
if($this->products_model->store_product($data_to_store) == TRUE){
$this->session->set_flashdata('flash_message', 'کاڵاەکەت بەسەرکەوتویی بارکرا، سوپاس بۆ بەشداربونت.');
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$data['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $data);
}else{
$this->session->set_flashdata('flash_message', 'not_uploaded');
}
}
}//validation run
else{
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$data['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $data);
}
}
else{
//form validation
$this->form_validation->set_rules('name', 'ناوی کاڵا', 'required');
$this->form_validation->set_rules('manufacturer', 'ناوی کۆمپانیای بەرهەمهێن', 'is_unique[manufacturers.manufacturers_name]');
$this->form_validation->set_rules('model', 'مۆدێل');
$this->form_validation->set_rules('category', 'جۆری کاڵا', 'required');
$this->form_validation->set_rules('price', 'نرخی کاڵا', 'required|numeric');
$this->form_validation->set_rules('stock', 'ذانە', 'required');
$this->form_validation->set_rules('description', 'ڕونکردنەوە');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$config['upload_path'] = './uploads/products/temp';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1200';
$config['max_width'] = '720';
$config['max_height'] = '576';
$config['multi'] = 'ignore';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('uploadedimages'))
{
$error = array('error' => $this->upload->display_errors());
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$error['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $error);
}
else
{
$manufacturers_data = array('manufacturers_name' => $this->input->post('manufacturer'),);
$manufacturers_id = $this->manufacturers_model->store_manufacture($manufacturers_data);
$data = array('upload_data' => $this->upload->data());
if (!$data['upload_data'][1]['full_path']) {
$data['upload_data'][1]['full_path'] = NULL;
}
if (!$data['upload_data'][2]['full_path']) {
$data['upload_data'][2]['full_path'] = NULL;
}
$data_to_store = array(
'name' => $this->input->post('name'),
'manufacturers_id' => $manufacturers_id,
'model' => $this->input->post('model'),
'categories_id' => $this->input->post('category'),
'sell_price' => $this->input->post('price'),
'stock' => $this->input->post('stock'),
'used' => $this->input->post('used'),
'description' => $this->input->post('description'),
'img' => substr($config['upload_path'], 1).'/'.$data['upload_data'][0]['file_name'],
'img1' => substr($config['upload_path'], 1).'/'.$data['upload_data'][1]['file_name'],
'img2' => substr($config['upload_path'], 1).'/'.$data['upload_data'][2]['file_name'],
'product_date' => date('Y-m-d H:i:s'),
'company_id' => $this->session->userdata('company_id'),
'uploader_ip' => $this->input->ip_address(),
);
//if the insert has returned true then we show the flash message
if($this->products_model->store_product($data_to_store) == TRUE){
$this->session->set_flashdata('flash_message', 'کاڵاەکەت بەسەرکەوتویی بارکرا، سوپاس بۆ بەشداربونت.');
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$data['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $data);
}else{
$this->session->set_flashdata('flash_message', 'not_uploaded');
}
}
}//validation run
else{
$data['featured_products'] = $this->products_model->get_featured_products(4, 1);
$data['featured_offers'] = $this->products_model->get_featured_products(4, 2);
$data['categories_name'] = $this->products_model->get_categories_name();
$data['main_content'] = 'pages/add_product';
$this->load->view('templates/template', $data);
}
}
}
else{
redirect('home/company_add_product');
}
}
}
这是模型:
function store_product($data)
{
$insert = $this->db->insert('products', $data);
return $insert;
}
但问题是当我上传产品时可以说
火灾,整个网站发生故障并发出500内部错误。 我的网站是在dreamhost上,我在崩溃后将文件上传到godaddy,它是相同的,给出500内部错误。但是当我上传整个网站时,我在崩溃之前备份了它,它又重新开始工作了。我不知道它看起来像这个代码打破了一些文件。我曾两次联系支持团队,他们说错误不在他们身边。company_do_upload()
答案 0 :(得分:0)
您所拥有的日志片段显示的错误不是由您的代码触发,而是由配置文件触发。 line 195
/dh/apache2/template/etc/mod_sec2/99_dreamhost_rules.conf
的内容是什么?我想如果你的代码中的某些东西实际上是在触发500错误,那么日志中会引用你的PHP文件。您的日志片段并未表明情况属实。
如果是您的代码,请在不同的地方调用日志记录功能并查看它的位置。这就是我在httpd日志对我没有帮助时所做的事情。这是我使用的日志记录功能:
function logit($msg){
try {
$fh=fopen('/tmp/file.log','a');
fwrite($fh,date("Ymd His")."\t$msg\n");
fclose($fh);
} catch (Exception $ex){
// Forget it!
} // try..catch
} // logit
它会自动为发送到文件的消息添加时间戳。该函数在每次调用后故意关闭日志文件以强制缓冲区刷新,以确保您的程序死亡,日志将尽可能最新。这帮助我摆脱了许多紧张的局面。我在例程的开头和结尾调用日志导致问题:
function foo(){
logit("Foo():start");
// do something
logit("Starting potential trouble: some potentially troublesome value='$bar'");
// The single quotes around $bar help if $bar is not assigned a value
// problem code
logit("Foo():done");
} //foo
请务必确保fopen()
调用中的目录和文件可由Web服务器进程写入!话虽如此,你是否有PHP将上传的文件放在company_do_upload()
的Web服务器可写的路径上?