Can't download files from public folder from Laravel 5.6 - php

I don't know what I am doing wrong here, but I can't for the life of me manage to get the download feature to work in Laravel 5.6
I have files saved to the public folder as you can see below:
On the webpage, these images show up correctly in HTML <img> tags and when I view the details of the image, it shows me that it points to https://mydomain.test/storage/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png.
However, when I try and download this file from the server, I constantly get an exception error about the file not existing (for example: "data":"The file \"public\/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png\" does not exist"). I have tried every combination of path string I can think of, but everything results in the same error.
I have tried using storage_path, I have tried using the original path, I've tried hard coding the path
[2022-09-08 09:58:55] local.ERROR: Failed to download media file: The file "/home/vagrant/Code/dras/storage/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png" does not exist
[2022-09-08 09:59:38] local.ERROR: Failed to download media file: The file "public/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png" does not exist
[2022-09-08 10:00:14] local.ERROR: Failed to download media file: The file "https://mydomain.test/storage/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png" does not exist
[2022-09-08 10:17:18] local.ERROR: Failed to download media file: The file "app/public/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png" does not exist
[2022-09-08 10:45:50] local.ERROR: Failed to download media file: The file "storage/public/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png" does not exist
The only combination that doesn't throw an exception about "file does not exist" is when I use the path
return response()->download( 'storage/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png' );
However, that command throws a totally different error:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::header() in file /home/vagrant/Code/dras/app/Http/Middleware/Cors.php on line 27

The path:"public/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png\ implies the conflict between windows and linux systems. There cant be both / and \ in a path. it must be either or. Unfortunately, i have been there and there is no easy way to get past this. you must use str_replace method to manually replace either (/) or () with the other. Check what your OS views as a valid file path first. it should be either: \public\LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png
or
/public/LIizYnRWEqYOgTPlzTxbmuSbTMNYIFrnjLP1YWVH.png
Edit: For future reference, this is what finally resolved the problem,
BinaryFileResponse in Laravel undefined

Related

OCR wrapper for php

I am using this for ocr. This is wrapper for Tesseract ocr(I previosly installed Tesseract itself).
At first i dowloaded it via composer and followed examples in repo and also several posts on SO itself. And all can show is in network tab failed to load response data.
My alternate approaches is that i tried downloading repo itself, then tried to call it from my index.php which for test purposes is situated in same folder where class TesseractOCR is. I tried with images in repo and also tried with black letters on white background images with simple text.
This SO post looks promising, but i'm unsure where OP's file with example code is residing...
use thiagoalessio\TesseractOCR\TesseractOCR;
//or//require "TesseractOCR.php";//if it's in the same dir as test.php
$content = new TesseractOCR('text.png');
$text = $content->run();
echo $text;
Did i miss something obvious? Any help is appreciated.
EDIT1: I tried using in win powershell cli. By putting text.png in directory where tesseract is installed, then calling shell with administrator privileges, subsequently typing in it tesseract text.png output which creates output.txt in same directory with recognized text from that image.
So tesseract its working, my implementation with php wrapper is not.
EDIT2:
Forgot to add, page itself shows:
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
Not sure why it happens.
Edit3:
My code:
try{
//use thiagoalessio\TesseractOCR\TesseractOCR;
require "./vendor/thiagoalessio/tesseract_ocr/src/TesseractOCR.php";
echo $temp;//It's value is set in TesseractOCR.php
$content = new TesseractOCR('text1.png');
$text = $content->run();
echo $text;
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
}
Value set in $temp variable is visible through state file path, so why TesseractOCRclass itself isn't?
Edit4:
Even if i put absolute path to TesseractOCR.php which holds class, in include statement, it doesn't work.
It throws this error:
Fatal error: Uncaught Error: Class 'TesseractOCR' not found in C:\xampp\htdocs\myocr\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\myocr\index.php on line 10
This is TesseractOCR.//echoed text from file that holds TesseractOCR class.
Inclusion path:
include ("C:/xampp/htdocs/myocr/vendor/thiagoalessio/tesseract_ocr/src/TesseractOCR.php");
If i use(which is suggested in repo readme, use thiagoalessio\TesseractOCR\TesseractOCR;, then it throws:
Fatal error: Uncaught Error: Class 'thiagoalessio\TesseractOCR\TesseractOCR' not found in C:\xampp\htdocs\myocr\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\myocr\index.php on line 10
My question is: How it hits test message, but won't hit TesseractOCR class?
EDIT5:
If i require_once "./vendor/autoload.php"; , it throws:
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract The current $PATH is C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\Eddie\AppData\Local\Microsoft\WindowsApps;;C:\Users\Eddie\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Eddie\AppData\Roaming\npm;C:\Users\Eddie\AppData\Roaming\Composer\vendor\bin;C:\Program Files\heroku\bin in C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php:48 Stack trace: #0 C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\TesseractOCR.php(26): thiagoalessio\TesseractOCR\FriendlyErrors::checkTesseractPresence('tesseract') #1 C:\xampp\ht in C:\xampp\htdocs\myocr\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
Btw, i added its patch to env variable:
I solved it!. My problem occurs that i didn't know about autoloaders in php.
Link that helped me is this.
My project structure is this:
Created project folder myocr.
After previous, downloaded latest stable version of Tesseract and installed it.
Depending on your system, you may be required to add value to your system env variable. You need to do that here
then
then
then
I'm assuming it self explanatory with images provided.
Next is getting TesseractOCR via composer:
composer require thiagoalessio/tesseract_ocr
Finally, before using code sample in repo, you need to call autoloader.
Index.php:
require_once('./vendor/autoload.php');//<-This!
use thiagoalessio\TesseractOCR\TesseractOCR;
$content = new TesseractOCR('text1.png');
$text = $content->run();
echo $text;
This worked for me. Crucial thing to look after is directory structure.
localhost > myocr > index.php with its code, and after using composer you'll get vendor dir. and it's content. Image path in new TesseractOCR('text1.png'); is directory where both index.php and image are located.

My dynamic site is not loading when the site is online but works well in localhost

I'm getting this error when my site is online
[host www.sitename.com] Backend fatal error: PHP Fatal error: require_once() [function.require]: Failed opening required 'admin/config/connection.php' (include_path='.:/opt/cpanel/ea-php53/root/usr/share/pear:/opt/cpanel/ea-php53/root/usr/share/php') in /home/mistrybu/public_html/index.php on line 373\n
The site works well in localhost but when its put online , the dynamic part is not showing.
I changed the php version from php7 to php5 in cpanel. Now the front end is working but the backend is not.
Can someone help me solve this error?
PHP version
Definitely do not go back to PHP5. Keep it to 7. If that means rewriting some of the existing code, so be it, it will make your site more secure and more future proof.
Error Message
Your require_once() method cannot find or access a particular file. This is most probably because:
File missing
The file (connection.php) doesn't exist in the given location (admin/config). Now keep in mind that as the location doesn't start with a /, it's going to be relative to where the require_once() method is being run from.
Since you're running require_once() from:
home/mistrybu/public_html/
it's going to look for the file here:
/home/mistrybu/public_html/admin/config/.
Does that location exist? Does the connection.php reside in the folder?
Folder mismatch
Try adding the following prefix to your path, and see if that makes a difference:
require_once $_SERVER['DOCUMENT_ROOT'].'/admin/config/connection.php';
File errors
Maybe the file exists, but for some reason, gives an error. Try running the following from your command line and see if you get any errors:
php -f admin/config/connection.php

MediaWiki 1.27 warning requiring SpecialUserLogin.php

I've updated my mediawiki from 1.26.2 to 1.27, the installation process finished ok, but when I try to access I received this error:
Warning:
require(/var/app/current/includes/specials/SpecialUserLogin.php):
failed to open stream: No such file or directory in
/var/app/current/includes/AutoLoader.php on line 81 Fatal error:
require(): Failed opening required
'/var/app/current/includes/specials/SpecialUserLogin.php'
(include_path='/var/app/current/vendor/pear/pear_exception:/var/app/current/vendor/pear/console_getopt:/var/app/current/vendor/pear/pear-core-minimal/src:/var/app/current/vendor/pear/mail_mime:/var/app/current/vendor/pear/mail_mime-decode:/var/app/current/vendor/pear/net_socket:/var/app/current/vendor/pear/net_smtp:/var/app/current/vendor/pear/mail:.:/usr/share/pear:/usr/share/php')
in /var/app/current/includes/AutoLoader.php on line 81
I have no idea why is this happening. If I check the files in my server they're there. I'm also having template issues if I choose vector I only get a messed up template, without styling.
I'm using PHP 5.6.
I hope someone can help me.
I just stumbled across this same exact error after upgrading to MW 1.27.
In my case, the SpecialUserlogin.php existed and all of the permissions were right BUT the word login was written in lowercase so the system thought this file didn't exist. So I just renamed the SpecialUserlogin.php to SpecialUserLogin.php and b00m, it worked!
As for your templating issues, check the common.css file. Copy paste everything out of there, so it's empty, if you don't use it. And check that you're calling your style files correctly in your template.

Mirror API database access issue

I just installed the Google mirror API. I have everything setup except after I log in to the API, I get this error message:
Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\mirror-client.php on line 33
Fatal error: Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' in C:\xampp\htdocs\util.php:62 Stack trace: #0 C:\xampp\htdocs\util.php(62): SQLite3->__construct('/tmp/database.s...') #1 C:\xampp\htdocs\util.php(26): init_db() #2 C:\xampp\htdocs\oauth2callback.php(41): store_credentials('107736579479351...', '{"access_token"...') #3 {main} thrown in C:\xampp\htdocs\util.php on line 62
It seems that the API can't create the database or do I need to create it?
I tried making a folder and database as it is set up in the config.php file "tmp/database.sqlite" but no luck.
Any ideas?
I figured out that you had to make your own database for it to work.
It can mean that the directory/folder you placed the sqlite file in (and the file itself) does not have the correct permissions. You need to make sure both the folder and the file have read and write permissions. The xampp directory in my environment has read/write permissions. You might want to place your database there, at least for testing purposes.
Note: The /tmp directory as mentioned in "/tmp/database.sqlite" is a Linux/Mac directory. You may want to change the value of $sqlite_database in the config.php file to point to a file in a Windows directory.

Cloudinary: Error in sending request to server-couldn't open file

In cloudinary php i have the required files and set my config too but when i try to upload a picture from php file
\Cloudinary\Uploader::upload("1.png");
i get error
( ! ) Fatal error: Uncaught exception 'Exception' with message 'Error in sending request to server - couldn't open file in C:\wamp\www\demo\src\Uploader.php on line 200
Exception: Error in sending request to server - couldn't open file "1.png" in C:\wamp\www\demo\src\Uploader.php on line 200
Call Stack
The uploader cannot find the file you are trying to upload. Try to put the 1.png file in the same directory as the php file and run:
\Cloudinary\Uploader::upload(realpath(dirname(__FILE__).'/1.png'));
Sounds like 1.png is hardcoded somewhere and your parameter is not taken into account. Try to do a project wide search for 1.png and see if you can replace that with a parameter.
I might as well provide an answer here because I had the same exact problem, contacted Cloudinary's support team, and their solution worked.
First, I have an images folder and keep all of them there.
\Cloudinary\Uploader::upload('images/image1.jpg');
That caused the same error you got. I then changed it to:
\Cloudinary\Uploader::upload("C:\\xampp\\htdocs\\test\\images\\image1.jpg");
That worked perfectly. However, I didn't want to use absolute paths, so that's why I contacted their support team. This is the code that works:
\Cloudinary\Uploader::upload( $_SERVER['DOCUMENT_ROOT'] . "/test/images/image1.jpg");
The test value in that string is the directory of my site, inside the htdocs folder.

Categories