Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot upload photo #47

Closed
douxlagithub opened this issue Feb 17, 2015 · 14 comments
Closed

Cannot upload photo #47

douxlagithub opened this issue Feb 17, 2015 · 14 comments

Comments

@douxlagithub
Copy link

Again, after tried out some tricks, I was unable to upload photo whether in an article and in photo album. Help please! I am so excited to develop this starter app, and I am still learning many things about laravel.

@cklam
Copy link

cklam commented Feb 17, 2015

Are you Wamp or Lamp based? If you are Lamp based hosting, you need to remove the firewall for post to work. please setenforce 0

@douxlagithub
Copy link
Author

I use EasyPHP for simple. http://www.easyphp.org/
How about using Intervention Image at http://image.intervention.io/ this plugin seems quiet pretty and very simple to use.

@zei
Copy link

zei commented Feb 17, 2015

At least thumbnail generation isn't checking if thumbnail folder exist. Try adding to beginning of app\helpers\thumbnail.php this:

$thumbnail_directory = dirname($thumbnail_image_path);
if(!file_exists($thumbnail_directory)) {
mkdir($thumbnail_directory);
}

@nextpulse
Copy link

I may have the same issue.

Did some debugging and noticed that Input::hasFile('picture') is always null in the controller.

@applecrusher
Copy link

I have been looking at this issue for some time now. I figured out the issue is that pictures can't be serialized when the ajax call is being made. I am personally trying to work on a fix now and I have had success with it. The only problem is now with the folder being named www instead of public, it will take me much more time to fix because that is where ultimately the pictures should be stored, I don't really want to think about converting it right now.

@douxlagithub
Copy link
Author

I hope somebody can implement third party image management like intervention at http://image.intervention.io/ This plugin is quiet easy to use. I couldn't figure it out in this starter app because of image naming convention is hashed with sha1. I was successful in implementing in my earlier app using laravel 4.2 and still trying for this laravel 5

@nextpulse
Copy link

@douxlagithub https://github.com/Intervention/image (it has support for laravel 5)
@applecrusher you may be right - but it should a form POST request in the code.
@mrakodol - what platform are you developing on? I am asking, as I am seeing a lot of platform dependent EOL in the source files. May also explain why it may work on one platform vs another (just speculating)

@applecrusher
Copy link

@nextpulse I am not sure what you mean by your statement to me. if you look at form.serialize(), files cannot be serialized, http://api.jquery.com/serialize/. That is why if you do Log::info(Input::all()), first import or "use Log;", you will see it missing the picture field in the log. The quick way I got around this was to simply avoid using the ajax call with the form. Rather I just closed the box and sent the form without preventing the default event. This is the quickest way of doing based on the way the code is written. However the draw back is no feedback on invalid saves. I had to also create the image directory as well.

@nextpulse
Copy link

@applecrusher I didn't realize the code was doing an ajax form request!! Now I see the issue. Found a few typos and js/css not found issue in the same file (modal.blade.php). May have to rework it to bypass the serialization for file upload. Anyhow, thanks for the info - now at least I know where to look.

@nextpulse
Copy link

So I did a quick 'hack' to make this work. For file upload forms, I added the id 'fupload' and amended modal blade. (Its ugly, but fixes it so I can at least proceed).

if (form.attr('id') == '' || form.attr('id') != 'fupload'){
$.ajax({
type : form.attr('method'),
url : form.attr('action'),
data : form.serialize()
}).complete(function() {
setTimeout(function() {
parent.$.colorbox.close();
window.parent.location.reload();
}, 10);
}).fail(function() {});
}else{
var formData = new FormData(this);
$.ajax({
type : form.attr('method'),
url : form.attr('action'),
data : formData,
mimeType:"multipart/form-data",
contentType: false,
cache: false,
processData:false
}).complete(function() {
setTimeout(function() {
parent.$.colorbox.close();
window.parent.location.reload();
}, 10);
}).fail(function() {});
};

@nextpulse
Copy link

BTW: the code in the PhotoController for saving the photo album/photos is not recommended. The reason is that it does not leverage the laravel 5 file system. (Meaning it does not take advantage of changes to the default storage - local, s3 etc)

http://mattstauffer.co/blog/laravel-5.0-cloud-file-drivers

IMHO: Probably best to take sometime to rewrite the file upload/save code - that that we understand it a bit better. (I'll add to this thread based on any new rewrites that I do).

@nextpulse
Copy link

To avoid hard coded paths (public_path() etc) in PhotoController, I took a deeper look at the Laravel 5 file system.

http://laravel.com/docs/5.0/filesystem

The best approach seems to be:

https://github.com/GrahamCampbell/Laravel-Flysystem

This means you don't have to hard code paths in PhotoController and have everything configurable via a config file. (Switch from local disk store to s3 etc).

@stojankukrika
Copy link
Collaborator

THX for advice and show me a bugs, but main problem is me not having enough free time to work on the project, I will tray to find some free time to do it well.
Until that, I hope that you understand me, and if someone have some free time to help, can make some poll request and I will approve it.

Sorry for waiting some new fixes :(

@applecrusher
Copy link

This is the fix for this issue. It requires changing 1 line and adding three more variables. This also allows optional feedback.

In resources/views/admin/layouts/modal.blade.php change the ajax to the following:

            $.ajax({
                type : form.attr('method'),
                url : form.attr('action'),
                data : new FormData(this),
                contentType: false,       
                    cache: false,             
                    processData:false
                }).complete(function() {
                    // Optionally alert the user of success here...
                    setTimeout(function() 
                        {
                            parent.$.colorbox.close();
                            window.parent.location.reload();
                        }, 10);

                }).fail(function(jqXHR, textStatus, errorThrown) {
                                    ....... add error status right here

Let me know how this works for everyone.

@zcosmin20 zcosmin20 mentioned this issue Dec 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants