I have updated from Symfony 3.4 to 4.0 and have verified the operation.
The image save function says "Completed", but the image is not saved.
Because the save destination was set to web/uploads,
In Image.php, I changed the image directory path from web
to public
, but it didn't change.
Is there anything else I need to change?
ImageController.php
public function saveAction(Request $request)
{
$response = new Response();
$imageService = $this->get("admin.imageService");
if ($token === $imageService->getImageToken($staffId, $uniq)) {
try {
$imageService->saveImage($image);
// Normal termination parameters #This is required for onComplete to fire on Mac OSX
$msg = $this->container->getParameter('uploadify_success');
} catch (\Exception $e) {
$msg = $e->getMessage();
$response->setStatusCode(400);
}
} else {
$msg = 'Access is illegal.';
$response->setStatusCode(400);
}
$response->send();
ImageService.php
public function saveImage(Image $image)
{
// Set the extension (already set when saving from an email attachment)
$ext = $image->getImageExtension();
if (!$ext && $image->getFileUpload()) {
$ext = $image->getFileUpload()->guessExtension();
$image->setImageExtension($ext);
}
// save
$this->entityManager->persist($image);
$this->entityManager->flush();
}
Image.php
private function getUploadRootDir()
{
// Absolute path to the location to save the uploaded file
return __DIR__.'/../../../../../../public/'.$this->getUploadDir();
}
/**
* Returns the image directory name
*
* @return string
*/
private function getUploadDir()
{
return 'uploads';
}
Postscript
index.html.twig
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('uploadifive/jquery.uploadifive.js') }}"></script>
<script src="{{ asset('js/image.five.js') }}"></script>
{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('uploadifive/uploadifive.css') }}">
{% endblock %}
{# contentBody #}
{% block contentBody %}
{{ render(controller('AppBundle:Hq/Image:manager')) }}
{% endblock %}
manager.html.twig
<div class="tabcontent">
<div class="operations">
{{ form_start(form, {"attr": {"id": "uploadForm"}}) }}
{{ form_widget(form.fileUpload) }}
{{ form_rest(form) }}
{{ form_end(form) }}
</div>
<div id="fileQueue"></div>
</div>