I am trying to upload a file to two different locations. The lcoations being /2x/
adn /3x/
. It uploads the file on 3x but doesn’t on 2x and throws this error:
The file was not uploaded due to an unknown error
Here is what i am doing:
$photo = $request->file('photo');
if (isset($photo)) {
if ($photo != null || $photo != '') {
$imageSize = getimagesize($photo);
$resolution = $imageSize[0] . 'x' . $imageSize[1];
if ($resolution == '300x300' || $resolution == '450x450') {
if (!file_exists(base_path('uploads/custom_avatar'))) {
mkdir(base_path('uploads/custom_avatar'), 0777, true);
}
$resolution = "3x";
$uploadPath = base_path('uploads/custom_avatar/' . $resolution . '/');
$otherImageResolution = '2x';
$otherImagePath = base_path('uploads/custom_avatar/' . $otherImageResolution . '/');
//echo $otherImagePath;exit;
// saving image
$fileName = $child->id . '_' . time() . '.png';
$photo->move($uploadPath, $fileName);
$photo->move($otherImagePath, $fileName);
// creating records
$childImage = Images::addPhoto($child->id, $fileName, $resolution);
$otherImage = Images::addPhoto($child->id, $fileName, $otherImageResolution);
if ($childImage && $otherImage) {
$result = Child::createChildResponseData($child);
Log::info('Child avatar added Successfully' . json_encode($childImage));
return response()->json([
'status' => $this->SUCCESS,
'response' => $result,
], $this->SUCCESS);
}
Any help?
asked Jul 7, 2017 at 7:24
2
Check your code if your file upload code is running two times.
I was facing the same issue & then I find that my file upload code is running two times.
after commenting one of them it’s working fine.
answered Aug 5, 2019 at 7:36
DEVDEV
2012 silver badges3 bronze badges
6
You can try this:
$request->file('photo')->move($destination_path, $file_name);
Add DIRECTORY_SEPARATOR between path and filename if needed and
copy that file at new location
copy($destination_path.$file_name, $new_path.$new_file_name);
answered Jul 20, 2017 at 7:31
Check your code if your file upload code is running two times.
You can check this part of the code. Make sure you type it correctly and not repeat it twice.
// Original size upload file
$section_image_file->move($folder, $section_image_name);
answered Mar 14, 2022 at 12:30
ufukufuk
3313 silver badges16 bronze badges
The file «ии.txt» was not uploaded due to an unknown error.
Это происходит когда я пытаюсь сохранить картинку с формы загрузки файлов.
foreach ( $request->file(‘files’) as $file){
$filename = $file->getClientOriginalName(); //$file->getClientOriginalName();
$idRecord = $problem->id;
//
$file->move(
‘/public/filesProblem/’.$idRecord.’/’, $filename
);
}
Самое странное, что одиночно файл сохраняет так ( $request->file(‘file’) и файл всего один то бишь). А мульти версия выдаёт такую ошибку и в log не особо помогает
#0 D:opeservOpenServerdomainsproblemnikappHttpControllersHomeController.php(182): SymfonyComponentHttpFoundationFileUploadedFile->move(‘/public/filesPr…’, ‘xD0xB8xD0xB8.txt’)
#1 [internal function]: AppHttpControllersHomeController->create_problem_post(Object(IlluminateHttpRequest))
#2 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingController.php(55): call_user_func_array(Array, Array)
#3 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingControllerDispatcher.php(44): IlluminateRoutingController->callAction(‘create_problem_…’, Array)
#4 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRoute.php(204): IlluminateRoutingControllerDispatcher->dispatch(Object(IlluminateRoutingRoute), Object(AppHttpControllersHomeController), ‘create_problem_…’)
#5 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRoute.php(160): IlluminateRoutingRoute->runController()
#6 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRouter.php(559): IlluminateRoutingRoute->run()
#7 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(30): IlluminateRoutingRouter->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#8 D:opeservOpenServerdomainsproblemnikappHttpMiddlewareCreateAnon.php(65): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#9 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): AppHttpMiddlewareCreateAnon->handle(Object(IlluminateHttpRequest), Object(Closure))
#10 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#11 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingMiddlewareSubstituteBindings.php(41): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#12 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateRoutingMiddlewareSubstituteBindings->handle(Object(IlluminateHttpRequest), Object(Closure))
#13 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#14 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareVerifyCsrfToken.php(65): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#15 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateFoundationHttpMiddlewareVerifyCsrfToken->handle(Object(IlluminateHttpRequest), Object(Closure))
#16 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#17 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateViewMiddlewareShareErrorsFromSession.php(49): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#18 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateViewMiddlewareShareErrorsFromSession->handle(Object(IlluminateHttpRequest), Object(Closure))
#19 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#20 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateSessionMiddlewareStartSession.php(64): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#21 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateSessionMiddlewareStartSession->handle(Object(IlluminateHttpRequest), Object(Closure))
#22 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#23 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateCookieMiddlewareAddQueuedCookiesToResponse.php(37): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#24 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateCookieMiddlewareAddQueuedCookiesToResponse->handle(Object(IlluminateHttpRequest), Object(Closure))
#25 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#26 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateCookieMiddlewareEncryptCookies.php(59): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#27 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateCookieMiddlewareEncryptCookies->handle(Object(IlluminateHttpRequest), Object(Closure))
#28 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#29 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#30 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRouter.php(561): IlluminatePipelinePipeline->then(Object(Closure))
#31 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRouter.php(520): IlluminateRoutingRouter->runRouteWithinStack(Object(IlluminateRoutingRoute), Object(IlluminateHttpRequest))
#32 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingRouter.php(498): IlluminateRoutingRouter->dispatchToRoute(Object(IlluminateHttpRequest))
#33 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php(174): IlluminateRoutingRouter->dispatch(Object(IlluminateHttpRequest))
#34 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(30): IlluminateFoundationHttpKernel->IlluminateFoundationHttp{closure}(Object(IlluminateHttpRequest))
#35 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareTransformsRequest.php(30): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#36 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateFoundationHttpMiddlewareTransformsRequest->handle(Object(IlluminateHttpRequest), Object(Closure))
#37 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#38 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareTransformsRequest.php(30): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#39 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateFoundationHttpMiddlewareTransformsRequest->handle(Object(IlluminateHttpRequest), Object(Closure))
#40 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#41 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareValidatePostSize.php(27): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#42 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateFoundationHttpMiddlewareValidatePostSize->handle(Object(IlluminateHttpRequest), Object(Closure))
#43 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#44 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareCheckForMaintenanceMode.php(46): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#45 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(148): IlluminateFoundationHttpMiddlewareCheckForMaintenanceMode->handle(Object(IlluminateHttpRequest), Object(Closure))
#46 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateRoutingPipeline.php(53): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(IlluminateHttpRequest))
#47 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminateRoutingPipeline->IlluminateRouting{closure}(Object(IlluminateHttpRequest))
#48 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php(149): IlluminatePipelinePipeline->then(Object(Closure))
#49 D:opeservOpenServerdomainsproblemnikvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php(116): IlluminateFoundationHttpKernel->sendRequestThroughRouter(Object(IlluminateHttpRequest))
#50 D:opeservOpenServerdomainsproblemnikpublicindex.php(54): IlluminateFoundationHttpKernel->handle(Object(IlluminateHttpRequest))
#51 {main}
Связь со мной:
Скайп(с аватаркой) — shyraks
Телеграм — @Mramoris или +7 999 260 13 20
-
Home
- php — The file «x.png» was not uploaded due to an unknown error
273 votes
1 answers
Get the solution ↓↓↓
I want to store a file with the move function in laravel, but I get this error : The file «x.png» was not uploaded due to an unknown error.».
I use this code :
$file->move(public_path('/files/'), $file->getClientOriginalName());
Thanks.
2021-12-15
Write your answer
410
votes
Answer
Solution:
consider using$file->store
instead, also the ‘/’ char after files in unnecessary
$file->store(public_path('/files'), $file->getClientOriginalName());
Share solution ↓
Additional Information:
Date the issue was resolved:
2021-12-15
Link To Source
Link To Answer
People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()
Didn’t find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
About the technologies asked in this question
PHP
PHP (from the English Hypertext Preprocessor — hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.