Trying to do something pretty simple but just need a bit of specific knowledge to get it to work.
I'm trying to submit an image in a post request to a post route in Laravel 5.5.
While retrieving a file from a request is easy with something like $file = $request->file('filename');,
Which will work with a html5 form that uploads a file and submits it to that route, what I am trying to do is upload a file via an API Blueprint.
I've unsuccessfully tried looking for the exact post data structure Laravel expects in order for a file to be retrieved with $file = $request->file('filename');,
Which I'm guessing is a standard, yet I have been unable to find an example of it as an API Blueprint.
If anyone has any pointers or suggestions, it would be much appreciated. Thanks!
submit an image in a post request to a post route in Laravel 5.5 use this code:
$imageTempName = $userdata->file('image_media')->getPathname();
$imageName = $userdata->file('image_media')->getClientOriginalName();
I think you need to try this process for upload file into the database within the directory using Laravel 5.
<?php
public static function upload_file(Request $userdata){
$imageTempName = $userdata->file('image_media')->getPathname();
$imageName = $userdata->file('image_media')->getClientOriginalName();
$path = base_path() . '/public/uploads/images/';
$userdata->file('image_media')->move($path , $imageName);
$data=array('media'=>$imageName);
$insert=with(new UserModel)->uploadFile($data);
}
?>
Related
I have been stuck on this for hours. Maybe my mind is tired. I hope someone can assist me. I am developing a Laravel application which connects to an external application that creates and edits invoices. One of my routes is supposed to allow a user to download a PDF invoice from this external application. My controller resembles the code below:
public function download(Invoice $invoice)
{
// Creates an instance of the remote invoice
$remoteInvoiceFile = RemoteInvoiceSoftware::find($invoice->id);
return response()->streamDownload(function () use ($remoteInvoiceFile ) {
// This calls the remote server and the server responds with the PDF file contents
$file = $remoteInvoiceFile->download();
echo $file;
}, 'file.pdf');
}
I read about the streamDownoad function from the Laravel documentation and implemented it the same way it was displayed. But I am getting an error where I am able to download a PDF file, however, not only is the file less than 5KB (the original invoice file is about 60KB), I also get an error when I try to open it. Something about the file being corrupt or not parsed well.
When I echo $remoteInvoiceFile->download() without using the streamDownload I get something like this:
Please help me figure what's going on and how I can fix this. Thank you!!
Have tried the API call as listed on Podio dev site to upload a file and I am not getting much joy.
I am trying to "Upload a file" in the first instance using the POST operation and passing the json with the source url to the endpoint as specified.
I can use other methods just fine but since there is little in the way or error feedback I am stuck I keep getting error 404
I have used - https://developers.podio.com/doc/files/upload-file-1004361
(have tried both GET & POST)
image of method with error i get
Upload file method that you are trying to use (https://developers.podio.com/doc/files/upload-file-1004361) is expecting file path which is supposed to be local file but not url.
Here is example of how it should be used:
http://podio.github.io/podio-php/api-requests/
$file = PodioFile::upload($path_to_file, $filename_to_display);
print 'File uploaded. The file id is: '.$file->id;
Here is another example on how to work with files:
https://developers.podio.com/examples/files
Well, I've uploaded an app to Heroku, and I've discovered that I can't upload files to it. Then I started to use Dropbox as storage option, and I've done a few tests, of send and retrieve link, and all worked fine.
Now, the problem is to use the uploadFile() method on DropboxAdapter. He accepts an resource as the file, and I did'nt work well. I've done a few tests, and still no way. Here is what I am doing, if anyone could me point a solution, or a direction to this problem, please. :)
Here is my actual code for the update user (Update the user image, and get the link to the file).
$input = $_FILES['picture'];
$inputName = $input['name'];
$image = imagecreatefromstring(file_get_contents($_FILES['picture']['tmp_name']));
Storage::disk('dropbox')->putStream('/avatars/' . $inputName, $image);
// $data = Storage::disk('dropbox')->getLink('/avatars/' . $inputName);
return dd($image);
In some tests, using fopen() into a file on the disk, and doing the same process, I've noticed this:
This is when I've used fopen() on a file stored on the public folder
http://i.imgur.com/07ZiZD5.png
And this, when i've die(var_dump()) the $image that I've tried to create. (Which is a suggestion from this two links: PHP temporary file upload not valid Image resource, Dropbox uploading within script.
http://i.imgur.com/pSv6l1k.png
Any Idea?
Try a simple fopen on the uploaded file:
$image = fopen($_FILES['picture']['tmp_name'], 'r');
https://www.php.net/manual/en/function.fopen.php
You don't need an image stream but just a filestream, which fopen provides.
I am using Zend Framework in PHP and want to create validation on file uploads, the process these uploads for storage on the backend server. What information should I expect the FileTranser phonegap plugin to post, so that I know how to process this in the back end? Can Anyone help on this?
My code might look something like this.... but without documentation of the specifics, it's hard to write the back end code and the phonegap documentation does not give enough information.
$form = new Project_Forms_Post();
$request=$this->getRequest();
if ($this->_request->isPost() && $form->isValid($this->_request->getParams())) {
$vals = $form->getValues();
$post = new Project_Model_Post($vals);
$post->save();
}
Zend Framework actually will process the file uploads as part of the form validation, so I just need to know basically, what name or names, as if coming from a form post with a input type=file, that the File plugin would attach to files.
Thanks
After spending quite a bit of time on this, I came up with a solution, this could probably be written a little better, such as putting a condition on $upload->receive() to do something on failure, but this works for now. I am using the Zend_File_Transfer class as trying to fool the form into accepting the file transfer through a file element just did not work I think because of the php file upload security in place etc.
$upload = new Zend_File_Transfer();
$upload->addValidator('MimeType', false, array('image/png', 'image/jpeg', 'image/gif', 'video/mpeg', 'video/mp4'));
//$upload->addValidator('Size', false, 200000);
$upload->setDestination(APPLICATION_PATH . "/../public/media/tmp");
$upload->receive();
$filename = $upload->getFileName();
$mimeType = $upload->getMimeType();
I'm writing a web app that at one point allows a user to upload a photo to a flickr account (mine). I want to do this without saving the intermediate image on the server my web app is on.
What I've got so far is a page which implements phpFlickr and accepts a POST from a simple html form. I use $_FILES['file']['tmp_name'] as the path for phpFlickr to use. Here's the code:
<?php
require_once("phpFlickr.php");
$f = new phpFlickr("apikey", "secret", true);
$_SESSION['phpFlickr_auth_redirect'] = "post_upload.php";
$myPerms = $f->auth("write");
$token = $f->auth_checkToken();
$phid = $f->sync_upload($_FILES['file']['tmp_name']);
echo "Uploading Photo..." . $phid;
?>
I'm guessing that the tmp file is being lost because of the redirect that happens when $f->auth("write") is called, but I don't know. Is there a way to preserve it? Is there any way to do this without saving the file to the server?
Answer: There is No way to directly upload a file to Flickr without saving it as an intermediate file.
I've moved on to using move_uploaded_file() followed by a flickr API call, and its working perfectly.
I've also managed to get it to play nice with the excellent Jquery Uploadify, which lets me send multiple files to it in one go.