Can you please help me this error,i am stuck in that error from two days. i have work in laravel multiple images upload.but whenever i upload the images it will show below error msg..
Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileDoesNotExist File D:\xampp\htdocs\abc\storage\prop_images/5f211fbd7fa1a_p1.jpg does
not exist
namespace Spatie\MediaLibrary\Exceptions\FileCannotBeAdded;
use Spatie\MediaLibrary\Exceptions\FileCannotBeAdded;
class FileDoesNotExist extends FileCannotBeAdded
{
public static function create(string $path)
{
--->>>> return new static("File `{$path}` does not exist"); <<<<<----
}
}
i have use some solutions like clear cache,config,
php artisan storage:link....also changes storage path.Given bellow is my image uploading code in controller.i have use dropzone media library to upload images.
foreach ($request->input('prop_images', []) as $file) {
$addProperty->addMedia(storage_path('prop_images/' . $file))->toMediaCollection('prop_images');
}
thank you in advance... :)
I was having the same issue and in the end, it was an error in my logic, that was calling twice the temporary file so, correctly, it was giving error on the second time, as the temporary file had already been removed.
Basically, check your code for "addMediaFromRequest()" calls and review if it's more than one call trying to use THE SAME UPLOADED FILE, as it's going to break.
You can see more details at https://github.com/spatie/laravel-medialibrary/issues/1062
Related
greeting to the community...so I´m developping a little compact pplication with Laravel. The problem is that I´m trying to load the image from the folder Storage, "Storage/Pets", I tried successfully with another controller, but this time..and I dont know what a fu..I´m doing wrong, It seems that the pic is not found,(although I get the file name from MySql) becouse I don´t receive warns from Laravel.. I´ll appreciate any help..any help is welcome..:))
I try to do my best with the explanation...
the Controller
The function to load the image
The routes
The View pet.blade.php
If it is needed I can add even more "screenshots", the lat one is the code from ctrl+U where the route path is available...
You should always try to post code as text, as it is text not images.
Now that you have figured out how to get the error for the requests that aren't working you can fix the issue.
Class 'App\Http\Controllers\Response' not found in file C:\wamp64\www\proyectos_Laravel\petcare_service\app\Http\Controllers\PetController.php on line 71
You didn't alias the Response class in your Controller:
use Response;
// or
use Illuminate\Support\Facades\Response;
Or (as mentioned in the comments) you can use the helper function instead of the facade:
response()
I'm working on a new website. This website will be a one pager. All my files I already load in through PHP into the main folder. But now I want to edit them and update them through WYSIWYG.
The UPDATE and SELECT are already working. I tested it on a page who stood on its own. All the one-pager files are stored in a folder and within the folder is also the file which loads all the files into it. I call them through a href which ends up giving the file an # in the address bar. There lies the problem. I can't access the #file with the function I wrote because that only can access files without starting a #. Is it possible to access it through my function?
I give the code if the question is too unclear because it's a bit of mess to implement all the files I use for this purpose.
Short recap: Can't access #domain with a PHP function. Is it even possible to access it.
<?php
class Home extends Controller {
protected function frontpage() {
$viewmodel = new HomeModel();
$this->returnView($viewmodel->frontpage(), true);
}
}
?>
this is the returnView from Controller:
protected function returnView($viewmodel, $fullview){
$view = 'views/'. get_class($this). '/' . $this->action. '.php';
if($fullview){
require('views/main.php');
} else {
require($view);
}
}
I'm new with overflow so I couldn't get the function into right place but with protected function frontpage I should access the file frontpage.php. Well it does do that but that's not the right directory because it's only visible throug a href which means the function should have been: protected function #frontpage which isn't possible.
This is actually not possible, as the anchor (#) isn't sent to the server and is handled by the browser itself.
The only possibility is to include some JavaScript magic to your project.
I have a laravel application that is still in the development stages. I am currently trying to generate a sitemap for the application using Spatie\Sitemap\SitemapGenerator but my code isn't working. This is my sitemap code in a file called GenerateSiteMap.php:
<?php
use Spatie\Sitemap\SitemapGenerator;
class GenerateSiteMap
{
public function generateSite()
{
$generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile('sitemap.xml');
return $generator;
}
}
It doesn't give me any errors when I run it, it just doesn't do anything. Any idea how I can fix it?
If your file is at public folder you need to add public_path
$generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile(
public_path('sitemap.xml'));
otherwise it might be a permission issue
I have a primary controller located in secure/application/modules/gps/controllers that has a constructor that looks like this:
public function __construct()
{
parent::__construct();
$this->load->model('gps_model');
Assets::add_module_js('gps', 'gps.js');
Assets::add_module_css('gps','gps.css');
if($this->input->get('clear') != false){
$this->session->sess_destroy();
}
}
My CSS file that I am trying to include is located in the folder secure/application/modules/gps/assets/css. The code executes fine without warning, but the CSS file does not get included for any methods. Is there a configuration setting the may override the assets directory, or is there some other reason it's not being found/added? (The JS file is not being added either. The bonfire base CSS files (screen.css) IS getting loaded fine.
We found the solution to our particular problem.
The assets/cache directory did not exist. Once the server could write (it must exist and be writeable!) to the [document_root]/bonfire/public/assets/cache directory all was good.
This is not a solution, but I have faced the same problem and found help with the below information.
It'll added in your page but can you just look on ctrl+u source where bonfire will auto rename your file.
For example : In my code I have added id_proof_master.css file like below.
public function __construct()
{
parent::__construct();
$this->auth->restrict($this->permissionView);
$this->load->model('id_proof_master/id_proof_master_model');
$this->lang->load('id_proof_master');
$this->form_validation->set_error_delimiters("<span class='error'>", "</span>");
Template::set_block('sub_nav', 'master/_sub_nav');
Assets::add_module_js('id_proof_master', 'id_proof_master.js');
Assets::add_module_css('id_proof_master', 'id_proof_master.css');
}
And it's working fine but when I have check in source view (ctrl+u) it will show file name like "id_proof_master_master_mod.min.css" so can you just check it out in source; maybe it'll show you with some other name like my file.
I have a problem in CodeIgniter, and that is that when an image is not found on the server, the instance of a controller is created (besides the one that called the view).
I know all this can sound confusing, so this is the code to observe what I'm saying. I did this changes to a clean 2.1.0 CI version:
Add a controller to override the 404 error page, I added this one:
// add application/controllers/Errors.php
Class Errors extends CI_Controller {
public function error_404() {
echo 'error';
}
}
// change routes.php
$route['404_override'] = 'Errors/error_404';
Use a controller that isn’t the default one with an unexisting image, I used this:
// add application/controllers/Foo.php
Class Foo extends CI_Controller {
public function index() {
echo '<img src="doesntexist.png" />';
}
}
I couldn’t figure out another way of debugging it, so I created a log to write the events on CodeIgniter.php:
// add on CodeIgniter.php line 356
$path = 'log.txt'; //Place log where you can find it
$file = fopen($path, 'a');
fwrite($file, "Calling method {$class}/{$method} with request {$_SERVER['REQUEST_URI']}\r\n");
fclose($file);
With this, the log that generates visiting the index function is the following:
Calling method Foo/index with request /test/index.php/Foo
Calling method Errors/error_404 with request /test/index.php/doesntexist.png
Which is the problem I have, an instance of the Error class is created.
that is that when an image is not found on the server, the instance of a controller is created
Not really. What I believe is happening is that, since you're using a relative path for the image (and calling it directly inside a controller, which is wrong because you're ouputting something before headers), your browser attach the image directly to the CI url, thus making this request to the server:
index.php/doesntexist.png
Which is (correctly) interpreted by CI as a request to a controller, which doesn't exists, and therefore it issues the error class.
You could do, in your actual code (I'd put the images in a view, though):
echo '<img src="/doesntexist.png" />'
using an absoluth path, or using the base_url() method from the url helper:
echo '<img src="'.base_url().'doesntexist.png" />
This should tell the server to fetch the right request (/test/doesntexist.png) and won't trigger that error.