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.
Related
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
I'm trying to implement the ability for a user to upload an image. I'll save that image to Google Storage. Then I'll use the GoogleStorageTools to get a public servable URL for the image so I can display it on my site.
I need to test this on localhost though. When I was previously using php5.5, I could use the dev_appserver.py and it would mimic the gs:// integration and let me create and interact with files as if I was running in the cloud.
However, I'm using php7.2 for this app which can't use the dev_appserver.py, I just have to run through php's built-in webserver. When I try to upload the file, I get a Google Storage error. This is the code in my script that receives the post with the uploaded file:
$storage = new StorageClient();
$storage->registerStreamWrapper();
$basefilename = uniqid().'-'.sanitize_string($_FILES['imagefile']['name']);
$gsfilepath = 'gs://#default#/images/'.$basefilename;
if ( ! move_uploaded_file($_FILES[ 'imagefile' ]['tmp_name'], $gsfilepath)) {
error_log('Failed to move uploaded file. ' . $_FILES[ 'imagefile' ]['tmp_name'] . ' => ' . $gsfilepath);
}
These are the errors I get when I try to run the move_uploaded_file() code:
Google\Cloud\Core\Exception\NotFoundException: Client error: POST
https://www.googleapis.com/upload/storage/v1/b//o?uploadType=resumable
resulted in a 404 Not Found response: Not Found in
/Users/kenny/myproject/trunk/server/gae/vendor/google/cloud-core/src/RequestWrapper.php
on line 263
Fatal error: Uncaught Google\Cloud\Core\Exception\NotFoundException:
Client error: POST
https://www.googleapis.com/upload/storage/v1/b//o?uploadType=resumable
resulted in a 404 Not Found response: Not Found in
/Users/kenny/myproject/trunk/server/gae/vendor/google/cloud-core/src/RequestWrapper.php
on line 263
Warning: move_uploaded_file(): Unable to move
'/private/var/folders/1k/8xt74j593ss9yxbtqrv925j40000gp/T/phpKsSN6q'
to 'gs://#default#/images/5c1be56fd752d-hold-on-to-your-butts.png' in
/Users/kenny/myproject/trunk/server/gae/testupload-upload.php on line
11
The bucket name #default# isn't valid in the Cloud Storage Stream Wrapper. As you can see in the error, the URI which the library is posting to is missing the Bucket ID.
To see why, refer to the StreamWrapper::openPath() method in google/cloud-storage.
The bucket name is represented as the host key in the parse_url return value. As is proved below, the gs URI you're providing is causing parse_url to fail:
php > $url = 'gs://#default/foo';
php > var_dump(parse_url($url));
bool(false)
I assume #default# is a helper which works in certain circumstances. Try providing the real bucket ID in the gs URI.
I have recently set up XAMPP. The setup was straightforward but I don't seem to know the correct tweak to allow it to speak to the outside web world.
No matter how I try to read an external URL, it tells me where to get off.
(In PHP) I've tried the simple file_get_contents route. When that failed, somebody pointed me to curl. I enabled that in php.ini but that failed too.
I get the very unhelpful "Unable to open file"
Fatal error: Unable to open "https://earth.esa.int/documents/10174/1514862/Swarm_Level-2_TEC_Product_Description" in C:\xampp\htdocs\includes\PdfToText.phpclass:1665 Stack trace: #0 #2 {main} thrown in C:\xampp\htdocs\includes\PdfToText.phpclass on line 1665
I know this seems like an error with the class PdfToText (above) but it's just a way of showing the error. Take the file from between the quote marks, try to load it and it's fine. It doesn't want to open files from the outside world no matter what's tried.
I assume that it's a port/proxy/something but I've Googled all day in and out of stackoverflow and I cannot see the same problem anywhere.
Quick fix:
Find your php.ini file:
php -i | grep "Loaded Configuration File"
look for allow_url_fopen and set it to On
allow_url_fopen = On
Explanation:
This error happens because when you use functions like file_get_contents or fopen, you are handling file pointers, what allow_url_fopen will let you do is, resolve the url, create a tcp connection and create a network file pointer to that tcp connection, which will be handled by php as it were a file.
For security reasons, this setting is disabled on some installations.
Check the docs:
http://php.net/manual/en/filesystem.configuration.php
This is my first post here. I followed instructions and explored all the internet on this topic, still didn't figure out the solution. Added interpreter as you can see on this screenshot:
I created PHP Web Application as visible here:
And after that I when I try to run it in any browser I get this message (Don't have reputation 10 so couldn't post it as 3rd picture):
"Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.20"
Please help me, I don't know what to do anymore. Thanks in advance!
EDIT 1:
So I figured out that my php file and all the other files (css, js, html, img) have to be in xamp/htdocs folder so I can run it manually by writing "localhost/filename.php" in address bar. It works only if my php file is exactly in htdocs folder. Otherwise when I try to run my file from folder where the rest of my project is and in address I add "localhost/projectfolder/homepage.php" I got message saying: "
Warning: Unknown: failed to open stream: No such file or directory in
Unknown on line 0
Fatal error: Unknown: Failed opening required 'D:/xampp/htdocs/Damir
Jelusić/homepage.php' (include_path='D:\xampp\php\PEAR') in Unknown on
line 0"
I couldn't find a solution to this. Also I would like to be able to run my php page just by clickin little chrome icon in phpstorm. Tell me if it is possible. Cheers!
In Dropbox api, this error occurs:
Warning: file_put_contents(dropbox/tokens/766tYP3FZu8IEv4d.token) [function.file-put-contents]: failed to open stream: No such file or directory in C:\xampp\htdocs\dropbox\dropboxupload.php on line 28
Authentication requiredhttps://www.dropbox.com/1/oauth/authorize?oauth_token=766tYP3FZu8IEv4d&oauth_callback=http%3A%2F%2Flocalhost%2Fdropbox%2Fdropboxupload.php%3Fauth_callback%3D1
How can this error be solved?
Errors are returned using standard HTTP error code syntax. Any additional info is included in the body of the return call, JSON-formatted. Error codes not listed here are in the REST API
Create folder at root name "tokens" and try again
warning is due to not having "tokens" folder in your dropbox directory at root level.
create one.
second Oauth doesnot work on a Local Machine .
try to Upload it on a server and try again .