Share you frontend code and backend code.
The upload destination folder does not appear to be writable.
how to solve when you want to upload an image in tinymce (textarea) error : The upload destination folder does not appear to be writable.
so I can't upload image files
@Randy_Johnson frontend
{!! Form::select('page_category', $pagesCategories, old('page_category'), ['class' => 'form-control', 'placeholder' => 'Choose One', 'required']) !!} --}}
<div class="form-group">
<label>Page Category</label>
<select name="pages_category_id" class="form-control select2" style="width: 100%;" required>
<option selected="selected">Choose One</option>
@foreach ($pagesCategory as $pag)
<option value="{{ $pag->id }}"> {{ $pag->name }} </option>
@endforeach
</select>
</div>
<div class="form-group">
<label>Name</label>
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required>
</div>
<div class="form-group">
<label>Content</label>
<textarea name="content" id="content" cols="30" rows="15"></textarea>
</div>
<div class="form-group">
<label for="formFile" class="form-label">Thumbnail</label>
<input class="form-control" type="file" name="thumbnail" id="thumbnail">
</div>
<button type="submit" class="btn btn-success"><span class="fa fa-save"></span> Save</button>
</form>
</div>
</div>
</div>
Backend
public function store(Request $request) { $request->validate([ 'pages_category_id' => 'required', 'name' => 'required', 'content' => 'required', 'thumbnail' => 'required|image', ]);
$input['content'] = (strip_tags($request->content));
$input = $request->all();
if ($image = $request->file('thumbnail'))
{
$destinationPath = 'uploads/pages/'; //arahfolder
$imageName = date('d-m-Y') . "." . $image->getClientOriginalName(); //namafile
$image->move($destinationPath, $imageName);
$input['thumbnail'] = "$imageName";
}
Pages::create($input);
return redirect('/pages')->with('success', 'Success Add Pages!!');
Are you on your local machine, and if so what operating system are you using. Try editing your code with the code below. $file->move(public_path('images'), $fileName);
public function UploadImage(Request $request)
{
// Validation rules
$validatedData = $request->validate([
'file' => 'required|file|mimes:jpeg,png,jpg,gif|max:2048', // Example rules - adjust as needed
]);
if ($request->hasFile('file')) {
$file = $request->file('file');
// Generate a random name for the file
$fileName = Str::random(25) . '_' . date('Ymd') . '.' . $file->getClientOriginalExtension();
// Move the uploaded file to the /images directory
$file->move(public_path('images'), $fileName);
// You can also store file details in the database or perform other operations
return "File has been uploaded successfully!";
}
return "No file uploaded.";
}
@Randy_Johnson The code I shared from local is safe, but when hosted it doesn't work
@andreans Okay, well try my code about, it seems you are having trouble with the destination folder. The code I use should store it into a writable folder.
If you really wanna go sys admin you can chmod -R u+rwx /uploads/pages/ the folder you want to write to. This is ill advised and may not work due to not having the privilege.
Also I feel that $destinationPath = 'uploads/pages/'; should be like this $destinationPath = '/uploads/pages';.
@Randy_Johnson oke I'll try first
@Randy_Johnson It's true that the content image appears, but on my website I have a thumbnail image but now the thumbnail image doesn't appear. what's the solution ?
Please or to participate in this conversation.