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

File is not saved #203

Closed
petrjirasek opened this issue Feb 9, 2014 · 7 comments
Closed

File is not saved #203

petrjirasek opened this issue Feb 9, 2014 · 7 comments
Labels

Comments

@petrjirasek
Copy link

Hi,

I would like to ask you if someone doesn't know where is the problem. I followed the configuration tutorial in doc and try to create a photo entity with the similar configuration.

Here is gist https://gist.github.com/Jirda/8901323

I have created a directory upload in the web directory but when I run the load code in a data fixture to create Photo entity, then the image is not saved and the upload directory is empty. Also, imageName is null.

Thank you for your notes.

@K-Phoen K-Phoen added the Support label Feb 9, 2014
@K-Phoen
Copy link
Collaborator

K-Phoen commented Feb 9, 2014

Your problem is related to #200

Basically, changing this line:

$photo1->setImage(new File(__DIR__ . "/../Files/image1.png"));

by this one:

$photo1->setImage(new UploadedFile(__DIR__ . "/../Files/image1.png", "image1.png"));

should be enough.

@petrjirasek
Copy link
Author

Thank you for your feedback. I have just changed the line and I got:
[Symfony\Component\HttpFoundation\File\Exception\FileException]
The file "image1.png" was not uploaded due to an unknown error.

Any advice?

@K-Phoen K-Phoen added the Bug label Feb 9, 2014
@K-Phoen
Copy link
Collaborator

K-Phoen commented Feb 9, 2014

This method is really "upload" oriented (the bundle was developed to handle file uploaded with symfony forms). I thought this quick hack could work but after reading the UploadedFile source code it's clear that it won't.

As it seems that the file is already present on your server, the bundle is currently unable to handle the work for you. It's indeed something that we should fix, but in the meantime you have no choice but to move the file and save its name in the entity yourself.

@petrjirasek
Copy link
Author

So when I set the image name to photo1.png and save the file to the destination directory, would be it ok?:)

Thanks.

@K-Phoen
Copy link
Collaborator

K-Phoen commented Feb 9, 2014

It should, yes :)

@ghost
Copy link

ghost commented Sep 2, 2015

Actually setting the parameter test=true to the UploadedFile constructor does allow you to "upload" a local file:

new UploadedFile($filePath, "image1.png", 'image/png', filesize($filePath), null, true);

This fixes the "not uploaded due to an unknown error" issue @petrjirasek described.

@gorvelyfab
Copy link

Thank @chriwup this works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants