When I want upload file with form in laravel, I cant remove file value from request.
This is my full code
if($request->hasFile('image')){
$string_name = str_random(12);
$image = $request->file('image')->move(getcwd().'/image/original',$string_name.'.'.$request->file('image')->getClientOriginalExtension());
$request->request->remove('image');
}
if($request->hasFile('thumbnail')){
$string_name = str_random(12);
$thumbnail = $request->file('thumbnail')->move(getcwd().'/image/thumbnail',$string_name.'.'.$request->file('thumbnail')->getClientOriginalExtension());
}
Portfolio::create($request->all());
but image or thumbnail file do not remove from $request. This means this line of code not working :
$request->request->remove('image');
I've tried many ways but the file does not get removed from the request.
Instead of removing the image from your $request before saving, you can explicitly mention what you would like to save to your model by using the ->only([]) method on $request.
Portfolio::create($request->only(['title', ...]));
This will allow you to specify exactly what you would like saved from the $request data.
You can do the reverse and use the ->except() method to remove the image too:
Portfolio::create($request->except('image'));
use this to remove the file
$request->offsetUnset('input_file_name');
or
$request->except('filename');
Related
So I want to add an header image to my document in PHPWord in Laravel.
So this is my code
public function generateDocx()
{
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$headerLogo = 'http://127.0.0.1:8000/img/logoAnevBulanan.png';
$section->addImage($headerLogo);
// Bunch of line to download the docx
}
And I got Maximum execution time of 60 seconds exceeded, when I try the other method from the documentation, I still got the same error. I try to use asset() helper from laravel and still did not work
Try getting your image using local path instead of URL
$source = file_get_contents('/path/to/my/images/earth.jpg');
$textrun->addImage($source);
Refer to documentation : https://phpword.readthedocs.io/en/latest/elements.html#images
Saving images under cloudinary( with cloudinary-laravel 1.0) I keep public_id in my database
and I want to get url(http or https), size, dimaentainal of this file by public_id
At reading this
/**
* You can also retrieve a url if you have a public id
*/
$url = Storage::disk('cloudinary')->url($publicId);
at
https://github.com/cloudinary-labs/cloudinary-laravel
I got ERROR:
Disk [CLOUDINARY] does not have a configured driver.
But I save images to cloudinary with storeOnCloudinaryAs method and in my .env I have
CLOUDINARY_URL=cloudinary://NNNNNNNNNNNN:AErjB_-XXXXXXXXX
CLOUDINARY_UPLOAD_PRESET=ml_default
and default file config/cloudinary.php
My config/filesystems.php has no any cloudinary parameters and can it be reason of my error?
Also it seems very strange for me that Storage::was used in this case, but I did not
find how get file url/other properties by public_id ?
Edited 1:
I added line
...
CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider::class,
...
in 'providers' block of ny config/app.php and cleared cach.
But still got
"Disk [CLOUDINARY] does not have a configured driver."
error.
applying changes into .env and clearing cache I try to debug from which line error is triggered in file vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php as :
protected function resolve($name)
{
$config = $this->getConfig($name);
\Log::info( varDump($name, ' -1 $name resolve::') ); // IT HAS ‘CLOUDINARY’ value
if (empty($config['driver'])) {
throw new InvalidArgumentException("Disk [{$name}] does not have a configured driver.");
}
But what is source for $config in this file?
config/filesystems.php ? In this file I have no any CLOUDINARY block. maybe I need to add it? But in which format ?
Thanks in advance!
Setting driver to lowercase
$cloudinaryUrl = Storage::disk(strtolower($imagesUploadSource))
fixed this error.
I'm trying to upload an image file . When i am calling my API to upload file using postman , getting error like Fatal error: Call to a member function file() on array.
I could not post this file to my Laravel controller .How to post files in Laravel. Anyone could help me to solve this issue?
Here is my controller function,
public function edit(Request $request){
$request = $request->input();
if(empty($request)) {
$request = json_decode(file_get_contents('php://input'),true);
}
$to_return = array();
$file = $request->file('files');
}
at this line $file = $request->file('files'); getting fatal error.
set method as post .. and at body ... change to option from form data to w-xxx-formurlencod ... and try ..
If you want to file uploads with Postman and Laravel, simply remove the Content-Type header setting in Postman.
set method as post
and at body ... select the radio that shows url encoded
see an image ... click on text set it as flie
i have codes like this
function download(){
$id = $this->uri->segment(3);
$dat = $this->mikland->gidiklanfoto($id);
foreach ($dat as $item){
$name = $item->foto;
$data = file_get_contents(base_url()."/uploads/".$name); // filenya
force_download($name,$data);
}
redirect('cikland/viewiklan/'.$id);
}
when the function are running, redirect cannot run.,
somebody can help??
i think is a simple thing but i dont know the trick., thank's before
At the end of force_download() there is an exit() statement, so no code after a forced download will run.
And you are trying to have several files downloaded at the same time - using some sort of multipart mime type, that might or might not work, but not in the given case, because CI's force_download() does not seem to support that.
An alternative to that would be creating a temporary archive file which contains all the files for download; please have a look at the official documentation on compression and archives for that.
If you'd want to send a redirection header along with the file, you'd have to do it like this:
function download(){
// add this somewhere befor the download
header('Location: '.site_url('cikland/viewiklan/'.$id));
$id = $this->uri->segment(3);
$dat = $this->mikland->gidiklanfoto($id);
// only first item is downloaded
foreach ($dat as $item)
{
$name = $item->foto;
$data = file_get_contents(base_url()."/uploads/".$name); // filenya
force_download($name,$data);
}
}
But the question would remain how the browsers would deal with a redirect and content: most likely you would only get the redirect.
You need load url helper.
$this->load->helper('url');
after
redirect("cikland/viewiklan/$id", 'refresh');
or
redirect("cikland/viewiklan/$id", 'location', 301);
Font: http://ellislab.com/codeigniter%20/user-guide/helpers/url_helper.html
redirect() method redirects to a URL. You need to pass it a full URL (as it uses the header() function which according to the RFC for HTTP1.1 requires a full URL.
so you need to hard code the full url like the given example - redirect('http://www.yoursite.com/cikland/viewiklan/'.$id);
I am using Laravel 4.
I have an old url that needs to be routable. It doesn't really matter what it's purpose is but it exists within the paypal systems and will be called regularly but cannot be changed (which is ridiculous I know).
I realise that this isn't the format url's are supposed to take in Laravel, but this is the url that will be called and I need to find a way to route it:
http://domain.com/forum/index.php?app=subscriptions&r_f_g=xxx-paypal
(xxx will be different on every request)
I can't figure out how to route this with laravel, i'd like to route it to the method PaypalController#ipbIpn so i've tried something like this:
Route::post('forum/index.php?app=subscriptions&r_f_g={id}-paypal', 'PaypalController#ipbIpn');
But this doesn't work, infact I can't even get this to work:
Route::post('forum/index.php', 'PaypalController#ipbIpn');
But this will:
Route::post('forum/index', 'PaypalController#ipbIpn');
So the question is how can I route the url, as it is at the top of this question, using Laravel?
For completeness I should say that this will always be a post not a get, but that shouldn't really make any difference to the solution.
Use this:
Route::post('forum/{file}', 'PaypalController#ipbIpn');
And then in the controller, use
public function forum($file) {
$request = Route::getRequest();
$q = (array) $request->query; // GET
$parameters = array();
foreach($q as $key => $pararr) {
$parameters = array_merge($parameters, $pararr);
}
}
You can then access the get parameters via e.g.
echo $parameters['app'];
you can use route redirection to mask and ending .php route ex:
Route::get('forum/index', ['uses'=> 'PaypalController#ipbIpn']);
Route::redirect('forum/index.php', 'forum/index');