I need help!! I'm facing a issue with uploaded files. I don't now how to download them properly...
I have a front end that uploads files using FormData. Then, in the controller, I simply save the file (a test.txt for example) using:
request()->file('attachment')->store('logs', 'public')
It saves an rqervdrertwer.txt where it should, BUT, the content of the file is set to a base64 string.
My problem is when I try to download the file.
How could I achieve that?
If I write in my controller:
$pathToFile = storage_path('app/public/logs/' . basename($log->file));
return response()->download($pathToFile);
Then it force the browser downloading the file, exactly as it is stored; I mean, the browser gets an base64 string instead of the original content.
So, how could give a download response with a decoded file? and if it is a .pdf or other format?
Or that is not the way to save the file? maybe Laravel has a better approach instead encoding with base64?
Please, help!
Thx!
EDIT
Ok, I checked that my problem only occurs when its a .txt file. If the user uploads a .pdf, a .docx, an image, etc, it works ok. So, i'll block any .txt upload :)
Related
I am not able to add image that is saved at a URL something like "http://host/img.png" using below code snippet:
section.AddImage(url);
However if I use url as a relative url of image that is present on my disk then this is working fine.
Is this limitation of MigraDoc?
Can someone provide workaround, code samples to over come this?
MigraDoc works with local files (relative or absolute paths), not with files that are somewhere on the Internet.
AddImage() needs a path, not a URL.
You can download the image from the URL and either store it in a local file or store it in a string using BASE64 encoding and pass that string to MigraDoc.
You will have control over accessing the image from the web and can properly deal with problems.
See this article on BASE64 encoding for MigraDoc images:
http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx
I send a pdf file to some customers. I want to know witch are opened my file. My dream will be to have a http request post inside the pdf to my server. But i search on some website without result.
Someone know if it's possible? And how i could do that?
Thanks a lot in advance
Instead of sending the PDF file, you might want to send a link (unique to each recipient) where the PDF can be downloaded. This link can log which of the recipients has downloaded the PDF.
This will be easier to set up and your results will be more trustworthy.
If i have a filename for a local file on the computer:
$img = "deskfile:///D%3A%2FSCANS%2F%23AUKT%2Fimg2014%2F2014-06+SP%2FEPSON007.jpg"
how can i upload it the server without using the "file selector"?
If i enter the file adresses in the url window of a browser i can display the image.
But if i load the image in tag they won't display. I've read it's becuse of restrictions in the browser.
I can't add a value caluse to the either.
Is there anyway to upload the image from the string?
Or can i at least open the correct directory in the "file selector" so the user wont have the browse the whole computer when looking for the file?
Yes there is a way. You can use the File API with Html5 and/or a polyfill for this to load the image in the browser before posting it back to the server. The best such polyfill that I know of is called Moxy/Plupload. It includes Flash and Silverlight fallbacks for older browsers.
You can display the image because it is stored locally in your computer. How do you know where is the image going to be in the user's computer. The only way to access the user's file system is through the file selector, once the user has selected a file you can then use any API to save that file in the server on your terms, but you will not be able to see each of your users file system from you page (security reasons). Could you elaborate more in what you are trying to accomplish? What exactly are you trying to do?
I am implementing a project to my site to allow users to upload image files (ai, pdf, jpeg, gif, tiff). I know this can be very risky but I was wondering what kind of security checks I should put in place to make sure these files to not cause my site any harm.
OR
Should I use something like dropbox to upload my images? If I do this is it possible to get these images whenever I want so I can display them within the browser to the user?
image uploads are fine, because you know what you want: An image
First rule is never to trust the client, so let the user upload the file (maybe you want to add an upload size limit).
Second, you have to ensure that the image is really an image so
Check the mime-type of the file (don't go by the file extension, use a real mime type check like the file shell command or an appropriate library)
To really make sure the file is OK, Open and Reprocess it using an image library like GD, ImageMagick etc. and save it to disk (keep in mind this needs some resource!). This will also filter out corrupted images.
An uploaded file usually doesn't harm the site itself but the users who download the file.
I've come across with a file uploading part of a project I worked.
Some high-level suggestions to complement sled's answer:
The mime type is set on base of the file extension, so it's no useful (as the file has not been uploaded yet to the server, the mime type is just a 'guess' in base of his extension).
So solutions would be:
Do the content check client-side (before sending the http-request)
When you get the whole file by HTTP do the check server-side before persisting to the disk.
Other Suggestions:
The simple file extension check
(wheter by filename or mime-type) is
the basic secutiry measure that also
has to be present.
Folder permissions: Don't allow execute permissions, don't allow the user to create new folders (as it might create a sub-folder with executing permissions).
I am trying to extract images from flash on the following web-site: http://meijer.shoplocal.com/meijer/default.aspx?action=entryflash&storeref=120
I noticed that every time I click on "Next image", an images is requested from sever. Sample URL is http://akimages.shoplocal.com/dyn_rppi/740.0.75.0/meijer/large/110206os_o_003_T1C1_2pw26.jpg
So, this URL is exactly what I need, but I don't know how to extract all these URLs from the .swf file I have. I don't have any experience with flash, but I think that URLs should be in the .swf file. I tried "grep '110206os_o_003_T1C1_2pw26' adspage_slider-2.swf", but didn't get any result :(((
Ivan,
Did you try a Flash decoder? It should allow you to access the code and respective resources. Another possible and easier way would be to use Fiddler2 to extract the URLs that you have clicked from the swf file. Still, before you move further, make sure that you're not breaking any of the site's Terms and Conditions.