Laravel在表单提交后注销

时间:2018-03-21 22:50:14

标签: php laravel-4.2

我有一个非常奇怪的问题。我有一个表单,其中几乎没有自动存在的图像,只是更改位置。这是正常的。但是当我尝试上传图片并提交表单时,它会将我注销。这是表格:

<div class="tab-pane" id="mainSlider" role="tabpanel">
                                        {{ Form::open( array('url' => URL::to('my-affiliate/save-main-slider'),  'id' => 'frmEditPageSettings', 'files' => true ) ) }}
                                        <div class="col-lg-12">
                                            <div class="panel panel-default">
                                                <div class="panel-heading">
                                                    <div class="push-right">
                                                        <button type="submit" style="visibility: hidden; margin-top: 0 !important" class="btn btn-primary btn-small"><i class="fa fa-fw fa-save"></i> SAVE SLIDER SETTINGS</button>
                                                        <select class="btn" style="float:right;width: 20%; padding: 5px;margin-top: 5px;" id="filterSlides">
                                                            <option value="3">Show All</option>
                                                            <option value="0">Show Active</option>
                                                            <option value="1">Show Inactive</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="panel-body">
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <!-- Tab panes -->
                                                            <div class="tab-content">
                                                                <div class="" id="mainSlider" aria-expanded="true">
                                                                    <div class="row">
                                                                        <div class="col-lg-12">
                                                                            <br /><br />
                                                                            <div class="form-group">
                                                                                <div class="row">
                                                                                    <div class="col-lg-6 dropzone" id="dropzone">
                                                                                        <div class="fallback">
                                                                                            <input name="file" type="file" multiple />
                                                                                        </div>
                                                                                    </div>
                                                                                    <div class="col-lg-6">
                                                                                        <ul class="images-path-container list-unstyled">
                                                                                            @if(count($mainslider) > 0)

                                                                                                <?php $i = 1; ?>
                                                                                                @foreach($mainslider as $image)
                                                                                                    <li>
                                                                                                        <div class="thumbnail" data-active="{{isset($image->show_image) ? $image->show_image : 1}}">

                                                                                                            <a class="remove-image btn btn-danger btn-xs" href="javascript:void(0)"><i class="fa-fw fa fa-remove"></i></a>
                                                                                                            <img src="{{ URL::to($imagesUrl.$image->imagename) }}" /><br />
                                                                                                            <input type="text" class="form-control" name="url[{{$i}}]" value="{{$image->url}}" placeholder="Slider URL" />                                                                                    @if($hasImages == true)
                                                                                                                <input type="hidden" name="image[{{$i}}]" value="{{$image->imagename}}"  />
                                                                                                                <input type="hidden" name="existing_image[{{$i}}]" value="1"  />
                                                                                                                <select style="margin-top:5px;" class="form-control" name="show_image[{{$i}}]">
                                                                                                                    <option value="1" {{ $image->show_image == 1 ? 'selected' : ''}}>Active</option>
                                                                                                                    <option value="0" {{ $image->show_image != 1 ? 'selected' : ''}}>Inactive</option>
                                                                                                                </select>
                                                                                                            @else
                                                                                                                <input type="hidden" name="image_to_copy[{{$i}}]" value="{{$imagesUrl.$image->imagename}}"/>
                                                                                                                <select style="margin-top:5px;" class="form-control" name="show_image[{{$i}}]">
                                                                                                                    <option value="1">Active</option>
                                                                                                                    <option value="0">Inactive</option>
                                                                                                                </select>
                                                                                                            @endif

                                                                                                        </div>
                                                                                                    </li>
                                                                                                    <?php $i++ ?>
                                                                                                @endforeach
                                                                                            @endif
                                                                                        </ul>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-sm-12">
                                            {{ Form::submit('SAVE', array('class' => 'btn btn-primary btn-small')) }}
                                        </div>
                                        {{ Form::close() }}
                                    </div>

这是控制器:

public function saveMainSlider(){
    AffiliateMainSlider::where('affiliate_id', Auth::user()->id)->delete();
    if(Input::has('image') || Input::has('image_to_copy')){
        if(Input::has('image')) {
            $images = Input::get('image');
            $show_image = Input::get('show_image');
            $existing_image = Input::get('existing_image');
            $urls = Input::get('url');
            $i = 1;
            AffiliateMainSlider::where('affiliate_id', Auth::user()->id)->delete();
            foreach($images as $k => $image) {

                $new_name = $image;

                if(isset($existing_image[$k]) && $existing_image[$k] == 0) {
                    $tmp = explode('.', $image);
                    $extension = end($tmp);
                    $path = "images/main_slider/".Auth::user()->id."/";
                    $unique_name = sha1(str_random(10));

                    $new_name = $unique_name . '.' . $extension;

                    if (!File::exists($path)) File::makeDirectory($path);

                    Image::make("tmp/{$image}")->resize(1920, null, true, true)->save($path . $new_name);
                }

                $mainslider = new AffiliateMainSlider();
                $mainslider->affiliate_id = Auth::user()->id;
                $mainslider->imagename = $new_name;
                $mainslider->url = $urls[$k];
                $mainslider->position = $i;
                $mainslider->show_image = isset($show_image[$k]) ? $show_image[$k] : 0;
                $mainslider->save();
                $i++;
            }


        }
        if(Input::has('image_to_copy')){
            $image_to_copy = Input::get('image_to_copy');
            $urls = Input::get('url');
            if(isset($image_to_copy) && count($image_to_copy) > 0){

                foreach($image_to_copy as $img_counter => $image){
                    $old_image = str_replace("images/main_slider/", "", $image);
                    $path = "images/main_slider/".Auth::user()->id."/";
                    if (!File::exists($path)) File::makeDirectory($path);
                    File::copy($image, $path.$old_image);
                    $mainslider = new AffiliateMainSlider();
                    $mainslider->affiliate_id = Auth::user()->id;
                    $mainslider->imagename = $old_image;
                    $mainslider->url = $urls[$img_counter];
                    $mainslider->position = $img_counter;
                    $mainslider->show_image = 1;
                    $mainslider->save();
                }

            }
        }
    }
    return Redirect::back()->with('success', 'Page settings saved successfully');
}

这也是路线,所以你可以看到我如何使用该方法:

Route::group(array('before' => 'auth|maintenance|force.ssl'), 
function()
{
    Route::post('/my-affiliate/save-main-slider', 'StoreController@saveMainSlider');
}

我使用Laravel 4.2。另外上传我使用dropzone.js,但它正确上传图像到tmp文件夹,所以没有问题。有谁知道可能是什么问题?这通常在我的本地工作,但不在测试或生产服务器上工作。 提前告知你们所有人的帮助

0 个答案:

没有答案