In Laravel 5, I want to upload files like pdf, jpeg, and also txt files etc. I see the uploading is working well with the file extension except .txt files. My code is as under;
$validator = Validator::make($request->all(), [
'itemImage' => 'mimes:jpeg,jpg,gif,png,bmp,svg,doc,docx,odt,xls,xlsx,pdf,txt |max:4096'
]);
I also tried by replacing the txt as text/plain but got the same problem.
Remove the space between txt and |.
The validation translator will split rules on |. However, because of the space, the last extension ends in an extra space. And that is why .txt files are not allowed, because they do not end in an extra space.
Related
For example : Suppose we have 4 files inside a folder,
1656088200108CONTPE_CONR.txt
1656174600239CONTPE_NTSL.txt
1656261000254CONTPE_PMLL.txt
1656174600114CONTPE_CONR.txt
I wanted to add 'CONTPE_' in the beginning of every file.
Then i want to replace the filename as :
CONTPE_1656088200108CONTPE_CONR.txt
CONTPE_1656174600239CONTPE_NTSL.txt
CONTPE_1656261000254CONTPE_PMLL.txt
CONTPE_1656174600114CONTPE_CONR.txt
But there are incremental files in the folder. So destination code shouldn't be static/pre-defined.
I tried to do various code like:
ren *CONTPE*.* CONTPE_*
ren *CONTPE*.* CONTPE_????*.*
All the above methods, replaces the first characters in filename with CONTPE, thus outputs are like CONTPE_000254CONTPE_PMLL.txt, which is basically trimming the actual filename however I wanted as CONTPE_1656261000254CONTPE_PMLL.txt.
Screenshot will describe the problem.
I would like to convert large number of html files from a directory to PDF using C#.
How to pass input file name and output file name which contains spaces.
Eg wkhtmltopdf.exe 'test file.html' 'test file.pdf'
This is working using command prompt but not working in C#. Please help how to pass file names with spaces in it. The exe is taking spaces in file name as delimiter.
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 using following code to update stock in Magento 1.7.0.1
After hours of investigation, I have realized that the code works perfectly but my csv is the problem.
Following is where the script is
http://www.sonassi.com/knowledge-base/magento-kb/mass-update-stock-levels-in-magento-fast/
I am using dos program to create csv file and it's creating blank spaces at the end of each line causing the script not to import properly.
"sku","qty","is_in_stock"
"prod1","11","1"
About csv looks correct but it each line has about 25 blank spaces that you don't see.
If I open csv and remove all the spaces, save it and import it using stock.php, everything works great.
DOS program is not able to get rid of those spaces...is there any way to remove it from php script?
For example like this:
$sFile = 'my.csv';
$aFile = file($sFile);
foreach ($aFile as $iLine => $sLine) {
$aFile[$iLine] = trim($sLine);
}
file_put_contents(
$sFile,
implode("\n", $aFile),
);