I am upload some files into my folder when i unlink the file doesn't unlink, what are the file name with space doesn't unlink and what are the file name have Parentheses doesn't unlink.
eg:- img4 (2).jpg, sample file.pdf
Any one give me a solution...
Thanks
Here is the solutions.
Php unlink() returning errors with encoded filepaths containing spaces
Try
unlink(urldecode($filepath));
or
$filepath = str_replace(" ", "\ ", $filepath);
unlink($filepath);
Related
I have some files in "public/uploads/somephoto.jpg". How to delete this file? I tried
unlink(url('/uploads/somefile.jpg'));
But it doesn't work.
if file in your public folder then
unlink(public_path('uploads/somefile.jpg'));
or if it is stored in storage folder then
unlink(storage_path('uploads/somefile.jpg'));
here url() retrun http url but for delete file edit file you need system path which will be get by storage_path() or public_path()
I'm using laravel 6.1 and when i use request()->file('file')->store('avatars') to store the file then it stores .xlsx file as .zip and .csv file as .txt . How to solve this problem?
My full code is-
$path = request()->file('file')->store('avatars');
$array = Excel::toArray(new CustomerImport, request()->file('file'));
$store_customers=Schema::getColumnListing('store_customers');
return view('pages.import.upload_customer',compact('array','path','store_customers'));
Actually there is a closed PR refering about this problem:
https://github.com/laravel/framework/issues/28381
You can try:
$request->file->getClientOriginalExtension()
I am using Laravel 4. I allow users to upload a file, which is programmatically renamed with some number and stored. I also allow them to download the files, though I am supposed to rename their file from some funny number to their name, and download it.
My problem is, how can I change filename just before its downloaded?
My code:
return Response::download($pathToFile, $name);
When I do that, the file is downloaded with unknown format.
The second $name parameter, needs to include the full filename (including the file extension). The download method does not automatically detect the extension from the file path and append it to the name, so that needs to be done manually. Something like this will work:
return Response::download(
$pathToFile,
$name . '.' . pathinfo($pathToFile, PATHINFO_EXTENSION)
);
When I try to upload image from the form , Laravel is creating directory out of image name. Here is my basic code:
$file = Input::file("image");
$file = $file->move(public_path(). "/img/".$file->getClientOriginalName());
//file name is IPC_diagram.png
When die and dump I got this:
'/var/www/php/frbit/l4blog/public/img/IPC_diagram.png/phpvEb9zk'
Now name of image is name of new folder and image is renamed to some random php string, and placed in that folder.
What is the problem. Maybe something related to Linux specific handling of files. Also I was looking into symfony code for this, and symfony is trying to crete new folder every time file is moved but I don't understand how it is related to my code.
Thanks for help.
Do not use dot. Use comma, like this:
$name = time() . $file->getClientOriginalName();
$file->move('uploads/posts/',$name);
I am trying to read a file in the same directory as the Perl script as input and read from it in Windows using Perl.
Code:
$inputFile = getcwd . "/" . <STDIN>;
open (FILE, chomp($inputFile)) or die "Cannot open $inputFile: $!\n";
#lines = <FILE>;
print "#lines\n";
The error I get is:
C:/Documents and Settings/username/workspace/test.pl No such file or directory
Even though that file definitely does exist in that exact form in that exact directory. I've also tried putting the "Documents and Settings" in quotes.
The return value from chomp is not the chomped value. Factor out the chomp to before open and you should be fine.
The getcwd is needless, by the way; the concept of current directory means where to look in the absence of a full path.