Im trying to perform a file upload and am having truble generating a route to tell the move_uploaded_file where to move the file. In my routing file (from within the bundle) i have:
endorsement_pics:
pattern: /images
defaults: { _resource: EndorseMeEndorsementBundle/Resources/public/images/endorsement_images }
And i do:
$url = $this->get('router')->generate('endorsement_pics');
Which generates the literal url http://www.example.com/endorsement/images
And the function
move_uploaded_file($_FILES['endorsement_image']['tmp_name'], $url."image1.jpg");
Which gives me the error:
Warning: move_uploaded_file(/newsite/web/app_dev.php/endorsement/imagesimage1.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in /home/content/24/9254124/html/newsite/src/EndorseMe/EndorsementBundle/Controller/DefaultController.php line 20
Any ideas?
You can’t move a file to a URL — it has to be a filesystem path. Using routes for this is wrong.
To upload a file to the public
webfolder, you could do the following. First, create a parameter inparameters.ymlfor the upload directory path:Then use the parameter for an upload: