为什么代码点火器路线不起作用,找不到404页面?

时间:2019-06-09 14:57:42

标签: php codeigniter post routes

我有一个表格来提交财产详细信息。我建立在CodeIgniter中,我的表单中有一个jquery脚本来检查表单是否有效,并使用dropzone提交图像。 但是,当我添加路线时,它不起作用。

$route['image-upload']['post'] = 'property/uploadImages';

这里 控制器:Property.php 方法 。 :uploadImages()

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>



uploadImages():

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;


}


当我调用网址http://www.cerdvillas.dev.cc/admin/image-upload/post时,它显示“ 404页面未找到”

1 个答案:

答案 0 :(得分:0)

您需要在.htaccess文件中指定基本重写。此外,该文件中的大多数代码都被注释掉了。 在您的.htaccess代码中使用它

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder.
    #Additionally this will allow you to create a System.php controller,
    #‘system’ can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn’t true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #This last condition enables access to the images and css folders, and the 
    robots.txt file
    RewriteCond $1 !^(index\.php|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

考虑阅读mod_rewrite documentation,以了解有关Apache mod_rewrite规则的更多信息