【发布时间】:2019-06-09 14:57:42
【问题描述】:
我有一个表格可以提交房产详情。我在 CodeIgniter 中构建,我的表单中有一个 jquery 脚本来检查表单是否有效,并使用 dropzone 提交图像。 但是当我添加路线时它不起作用。
$route['image-upload']['post'] = 'property/uploadImages';
这里 控制器:Property.php 方法 。 : 上传图片()
uploadImages() :这里我上传来自 dropzone 拖放文件上传的图像。
我的 .htaccess 文件
<IfModule mod_rewrite.c>
# Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/codeginiter/is
# Restrict your site to only one domain
# !important USE ONLY ONE OPTION
# Option 1: To rewrite "www.domain.com -> domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Option 2: To rewrite "domain.com -> www.domain.com" uncomment the following lines.
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#RewriteCond %{HTTP_HOST} (.+)$ [NC]
#RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Remove index.php from URL
#RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
#RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
#RewriteRule ^index\.php(.*)$ $1 [R=301,NS,L]
# Keep people out of codeigniter directory and Git/Mercurial data
# RedirectMatch 403 ^/(system|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
</IfModule>
上传图片():
function uploadImages()
{
$this->load->helper('url');
if($this->input->post() != NULL ){
$data = array();
$config['upload_path'] = 'property-images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['max_size'] = '2048'; // max_size in kb
foreach($_FILES['file']['name'] as $key => $value) {
$config['file_name'] = $_FILES['file']['name'][$key];
// Load upload library
$this->load->library('upload',$config);
// File upload
if($this->upload->do_upload('file')) {
// Get data about the file
$uploadData = $this->upload->data();
$filename = $uploadData['file_name'];
$propertyId = 1;
$imageData = array('path'=>$imgPath, 'propertyid'=>$propertyId);
$result = $this->property_model->uploadImages($imageData);
}
}
return $result;
}
当我调用 url http://www.cerdvillas.dev.cc/admin/image-upload/post 时,它显示“404 Page Not Found”
【问题讨论】:
标签: php codeigniter post routes