CodeIgniter - 图像提交按钮不起作用

问题描述 投票:0回答:3
html codeigniter form-submit
3个回答
0
投票

是否适用于所有浏览器?还是IE特定的?如果您添加一个 onclick 事件只是为了测试呢?

onclick="javascript:document.formidhere.submit()"

我建议使用

<input type="submit" />
或我的偏好是使用
<button type="submit>
,因为浏览器与
<input type="image" />
不一致,只需使用以下内容设置按钮样式:

button{
    background:url('/images/subscribe_free.jpg') no-repeat;
    height:29px;
    width:207px;
    border:0;
}

0
投票

尝试添加

value="trialSubmit"
以获取要提交的图像。似乎对我有用。

您还可以看看这个答案是否有帮助: 图像提交按钮


0
投票
**inside the view(as comerciales in my case)**, 



    <form action= "<?php echo site_url()?>/admin/doupload"  method="post" enctype="multipart/form-data" >
  <b>  Select the image to upload( Maximum size 500 kb, jpg, jpeg): </b>
    <input   style="color:#00A76F" type="file" name="fileToUpload" id="fileToUpload">
   <div  class="input-group" style="left:10%;width:85%;">

 <input class="btn btn-success pull-right" style="background:#00A76F" type="submit" value="Upload Image" name="submit">



</div>


</form>
   <div class="modal-body">
                    <div id="user_data">
                      <?php
                      if (!empty($massage)){
                          echo $massage ;

                      }
                        ?>
                    </div>

**inside the controller define a method**

    public function doupload(){
       $root1 = $_SERVER['DOCUMENT_ROOT'];;

        $target_dir =  $root1."/nawaloka/uploads/";

             // $target_dir =  $root1."/nawaloka/application/";
          $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if file already exists
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
   $data['massage']= "Sorry, your file is too large.";
            $partials = array('content' => 'Admin/comerciales');
            $this->template->load('template/admin_template', $partials,$data);

    $uploadOk = 0;
}
if (is_dir($target_dir) && is_writable($target_dir)) {

    // do upload logic here
} else {
    echo 'Upload directory is not writable, or does not exist.';
}



// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "jpeg" ) {
     $data['massage']= "Sorry, only JPG, JPEG files are allowed.";
            $partials = array('content' => 'Admin/comerciales');
            $this->template->load('template/admin_template', $partials,$data);

    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
   $data['massage']= "Sorry, your file was not uploaded.";
            $partials = array('content' => 'Admin/comerciales');
            $this->template->load('template/admin_template', $partials,$data);

// if everything is ok, try to upload file
} else {
            array_map('unlink', glob("/var/www/html/nawaloka/uploads/*"));

    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],"/var/www/html/nawaloka/uploads/shamith.jpg")) {
           $data['massage']= "The image ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
            $partials = array('content' => 'Admin/comerciales');
            $this->template->load('template/admin_template', $partials,$data);


        //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {

             $data['massage']= "Sorry, there was an error while uploading your file.";
            $partials = array('content' => 'Admin/comerciales');
            $this->template->load('template/admin_template', $partials,$data);
    }
}




}
© www.soinside.com 2019 - 2024. All rights reserved.