I am trying to store a file in the following path "public/uploads/images" with lumen.
Here is my code
if($request->hasFile('photo')){
$file = $request->file('photo');
$fileName = time().$counter.'.'.$request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move('/uploads/images', $fileName);
return $fileName;
}
But no file is moving to the path. only the file name is returned. What is the problem and how to solve?
try to use the public_path function to upload it into public folder.
Example:
$request->file('photo')->move(public_path("/uploads"), $newfilename);
Visit https://laracasts.com/discuss/channels/laravel/image-upload-using-storage-function-to-public-folder
Related
I need to set $destination path to outside project need to copy folder from project file to computer location i have already tried using copy directory function
public function approovenew()
{
$source = "themes/call";
$destination = "/new-theme";
File::copyDirectory(base_path($source), base_path($destination));
}
Try to do this it will help you out
File::copyDirectory(__DIR__ . '/../whatever'$source, __DIR__ . '/../../$destination');
I am using move_uploaded_file function to save my file into two folders, the folders name are uploads_meeting_document and uploads_filing_file. It just can let me upload my file to this folder name uploads_meeting_document, it can't save to uploads_filing_filefolder. Anyone can guide me which part I have problem in below the coding:
<?php
require_once("../conf/db_conn.php");
// Getting uploaded file
$file = $_FILES["file"];
// Uploading in "uplaods" folder
$pname = date("ymdhi")."-".$_FILES["file"]["name"];
//$title_name = $_FILES["file"]["name"];
$tname = $_FILES["file"]["tmp_name"];
$uploads_dir = 'uploads_meeting_document';
move_uploaded_file($tname, $uploads_dir.'/'.$pname);
$uploads_dir2 = 'uploads_filing_file';
move_uploaded_file($tname, $uploads_dir2.'/'.$pname);
?>
Below is my file path need to save to these folders(red arrow there)
In your example, the second move_uploaded_file does not work, because the file was already moved to /upload_meeting_document
You will need to copy your file from there:
...
$uploads_dir2 = 'uploads_filing_file';
copy($uploads_dir.'/'.$pname, $uploads_dir2.'/'.$pname);
In case this does not work, you may have insufficient permissions for the /uploads_filing_file directory. Chech its owner and permissions.
i am creating file upload script and saving the file path to the sql, i use this script
$location = 'files/' . $file_name;
$full_path = realpath($location);
It return
D:xampphtdocsau
why theres no slash, am i doing it wrong
I am having a problem with move_uploaded_file().
I am trying to upload a image path to a database, which is working perfectly and everything is being uploaded and stored into the database correctly.
However, for some reason the move_uploaded_file is not working at all, it does not produce the file in the directory where I want it to, in fact it doesn't produce any file at all.
The file uploaded in the form has a name of leftfileToUpload and this is the current code I am using.
$filetemp = $_FILES['leftfileToUpload']['tmp_name'];
$filename = $_FILES['leftfileToUpload']['name'];
$filetype = $_FILES['leftfileToUpload']['type'];
$filepath = "business-ads/".$filename;
This is the code for moving the uploaded file.
move_uploaded_file($filetemp, $filepath);
Thanks in advance
Try this
$target_dir = "business-ads/";
$filepath = $target_dir . basename($_FILES["leftfileToUpload"]["name"]);
move_uploaded_file($_FILES["leftfileToUpload"]["tmp_name"], $filepath)
Reference - click here
Try using the real path to the directory you wish to upload to.
For instance "/var/www/html/website/business-ads/".$filename
Also make sure the web server has write access to the folder.
You need to check following details :
1) Check your directory "business-ads" exist or not.
2) Check your directory "business-ads" has permission to write files.
You need to give permission to write in that folder.
make sure that your given path is correct in respect to your current file path.
you may use.
if (is_dir("business-ads"))
{
move_uploaded_file($filetemp, $filepath);
} else {
die('directory not found.');
}
I'm using Laravel to upload an image to my folder.
$file = Input::file('largeImage');
$filePath = '/uploads/'.date("Y/m").'/'.time().'/';
$path = $filePath;
$file->move($path, $file->getClientOriginalName());
The image is successfully uploaded.
Now when I try to access it:
http://localhost:8080/uploads/2015/01/1420644761/10377625_673554946025652_6686347512849117388_n.jpg
I'm having the Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException error.
I even tried http://localhost:8080/public/uploads/2015/01/1420644761/10377625_673554946025652_6686347512849117388_n.jpg
But the same error. What might be the problem? I checked the uploads folder and the image is there.
You need to add a call to public_path helper:
$filePath = public_path() . '/uploads/'.date("Y/m").'/'.time().'/';
Otherwise it will place it in the app root, I think.
This worked for me:
$file = Input::file('largeImage');
$filePath = '/uploads/'.date("Y/m").'/'.time().'/';
$filename = $file->getClientOriginalName();
$path = public_path().$filePath;
$file->move($path, $file->getClientOriginalName());
Ok, so it IS a Routing Issue. To solve this particular one, define a Route::get that navigates to your file.
Route::get("/download/{year}/{month}/{time}/{filename}", "Controller#downloadFile");
Then you'll need a function in that controller that handles the file download:
public function downloadFile($year, $month, $time, $filename){
$path = public_path()."/uploads/".$year."/".$month."/".$time."/".$filename".jpg";
// Should equate to: "/uploads/2015/01/142064476110377625_673554946025652_6686347512849117388_n.jpg
return Response::download($path, 'image.jpg');
}
Which in theory should work for your needs. The path may need to be modified to fit your needs but this should be the general idea. Test that out and let me know if it works.
Note
This isn't the best way to handle downloads, as you need to know the exact filename of the file you want, but it points you in the right direction.