PHP - Cannot read uploaded temporary file - nginx

I'm holding a mail service on my VPS who has a web interface by Roundcube
But I recently found that my Roundcube cannot upload avatars of contacts correctly (which was my first try of uploading avatars). So I had a look of the code and found that it failed when reading properties of the uploaded temporary picture file.
To figure out whether it was caused by Roundcube or not, I wrote a simple script.
<html>
<body>
<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="file" name="test">
<button type="submit">Upload</button>
</form>
</body>
</html>
<?php
var_dump($_FILES);
var_dump(file_exists($_FILES['test']['tmp_name']));
// read the properties by GD, as what Roundcube does
$props = getimagesize($_FILES['test']['tmp_name']);
var_dump($props);
And the output was:
array(1) {
["test"]=> array(5) {
["name"]=> string(23) "kanakurayui_2_small.png"
["type"]=> string(9) "image/png"
["tmp_name"]=> string(14) "/tmp/php7OxqPq"
["error"]=> int(0)
["size"]=> int(49294)
}
}
bool(false)
bool(false)
It looks like that the file was immediately deleted after uploaded, however I could call move_uploaded_file() to move the temporary file to another directory (so the mail attachment is functioning properly).
I'm running Ubuntu 14.04 with Nginx 1.6.2 and PHP-FPM 5.6.7 from repositories of LaunchPad. And the script works correctly on my local machine whose environment is exactly the same.
I think the problem is caused by some certain configuration of Nginx or PHP, but after checking the configuration files, I could only find configurations about the size and time limit.
I'm really confused now. Please help, thanks.
UPDATE
Apache 2.4 + PHP works properly on the same VPS.

I finally solved the problem myself. Thanks #insanebits for reminding.
I had a look at the Nginx log and found the following message:
PHP message: PHP Warning: getimagesize(): open_basedir restriction in effect. File(/tmp/php1PACw4) is not within the allowed path(s): (/var/www) in /var/www/test/upload.php on line 5
So I moved the temporary directory to /tmp/php and add /tmp/php to the open_basedir setting in php.ini
The reason why it worked on my local machine was that my local PHP configuration was a copy for development and the open_basedir was commented out.

Related

Lando has trouble accessing a URL from a non-Lando app on my system

My company has software that runs within Docker on my system, but is not using Lando. This software is serving some data via the URL:
http://local.relay.cool:8081/clicks-bff/api/ads/
I can hit this URL in an anonymous browser, cURL it from the terminal, and load it via Postman and it returns the expected data.
I'm running Lando with the Wordpress recipe and I'm developing a plugin. This plugin can hit external URLs and retrieve data, I've tried with several different ones just to confirm.
However when Lando attempts to hit the URL listed above I get a WP_Error:
object(WP_Error)#1269 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(58) "cURL error 28: Resolving timed out after 5514 milliseconds" } } ["error_data"]=> array(0) { } }
Here's the .lando.yaml config block:
name: my app name
recipe: wordpress
config:
webroot: wordpress
Is there some configuration option that I'm missing to allow Lando access to another URL on my machine?
From your question, it sounds like the URL you're trying to access is running on a non-Lando docker container on your machine.
This means routing from your Lando instance to the service will be a bit different that usual. You should be able to accomplish this the same way you would access localhost endpoints. As explained in this Lando issue on GitHub, you must use the $LANDO_HOST_IP environment variable to route to local services.
Since your containers are all running inside of a light hyper-v instance you'll need to know the hostname or IP of the host machine. Generally we set $LANDO_HOST_IP to your computer . . .
So try something like this (assuming you're using PHP's curl):
curl_init('http://' . $_ENV["LANDO_HOST_IP"] . ':8081/clicks-bff/api/ads/');

Open files in PHPStorm with Vagrant+Symfony application

I know you can open files from Symfony profiler or exception file links using this in project/app/config.yml :
framework:
ide: "phpstorm://open?file=%%f&line=%%l"
More info: http://developer.happyr.com/open-files-in-phpstorm-from-you-symfony-application
However as I'm using vagrant, the file path of the server doesn't match my host.
I have created a PHP web application server in PHPStorm with the propper path mappings, but still doesn't work.
Any ideas?
Thanks
When running your app in a container or in a virtual machine, you can tell Symfony to map files from the guest to the host by changing their prefix. This map should be specified at the end of the URL template, using & and > as guest-to-host separators:
// /path/to/guest/.../file will be opened
// as /path/to/host/.../file on the host
// as /path/to/host/.../file on the host
'phpstorm://%f:%l&/path/to/guest/>/path/to/host/&/foo/>/bar/&...'
Symfony FrameworkBundle Configuration - IDE
The answer given by Jeffry no longer works unfortunately :(. When In configure that with my paths the profiler throws:
ParameterNotFoundException
You have requested a non-existent parameter "f:".
I have configured the path according to this line in the SF docs: This map should be specified at the end of the URL template, which results in this:
phpstorm://open?url=file://%%f&line=%%l&/path/to/guest/>/path/to/host/
However, it does open PHPStorm, but phpstorm does not open the file, so i'm a bit stuck here now.
This solves the issue with the file not opening in PhpStorm from a Vagrant:
phpstorm://open?file=%%f&line=%%l&/path/to/guest/>/path/to/host/
Source: https://youtrack.jetbrains.com/issue/IDEA-65879

Artifactory has lost track of local artifacts

I'm using Artifactory OSS 4.1.0 and Java 1.8.0_51.
When I try to download one of my local artifacts from the Artifactory web interface, I get this:
{
"errors" : [ {
"status" : 500,
"message" : "Could not process download request: Binary provider has no content for 'bab1c4e18f6c5edfb65b2503a388dea2fed0deb8'"
} ]
}
But I found this file in my Artifactory data area: ./files/ba/bab1c4e18f6c5edfb65b2503a388dea2fed0deb8, and upon further inspection it is the WAR file I tried to download.
I've come across other people on the web with the same error message, but their issue was with caching external artifacts, and their workaround was to delete the cache.
Does anyone have an idea what's going on and how I can fix the problem? BTW, I did stop and restart our Artifactory server, but with no noticeable difference.
Artifactory doesn't store the binaries under ./files directory, but under $ARTIFACTORY_HOME/data/filestore.
It looks like you had a symbolic link from the files directory to the filestore directory and this link was deleted.

White page when deploying Symfony2 Project

After I finished my project of symfony2 on windows I wanted to deploy it on a digitalocean server with Linux-Ubuntu OS. But there are some problems I can't figure them out. Please help me soon.
I uploaded the web folder files to folder html on server and other files (src , app , bin, vendor) to www folder. I also followed the instructions on config.php and solved the problems. But yet:
1- When I trying to type url : ip_address/app.php/ on browser a white page comes. No page and No error!
2- When I want to clear the cache in production env using the putty this error happens. ( Unable to write in the "C:/wamp/www/my-project/app/cache/prod" directory) but there is no such problem when clearing on localhost (I think this problem is because of transferring the project from windows to linux)
Please help me.
You probably have some errors (maybe cache directory).
For testing open the file web/app_dev.php and comment this:
/*if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !in_array(#$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
*/
Now you can access your page via ip_address/app_dev.php/ and see errors. When you finish, don't forget to uncomment this.
If you have problems with cache, then I suggest you to upload code without cache directory. Then create this directory in the server and give it right permissions.

Drupal: The selected file intersection.png could not be uploaded

I don't understand why I get this error when I upload images...
The selected file intersection.png could not be uploaded. The file is not a known image format.
It is just a png file, and the problem came when I moved the website on the server. On localhost everything was perfect.
1) I've deleted the "files" folder and created it again with a php script (to make the server the owner)
2) drupal automatically creates 2 folders into it (imagecache and temp) so I assume it has the privilegies to write into it.
3) I've changed the temporary folder in Settings > Filesystem from "/tmp" to "temp", since I got an error before (probably the /tmp folder on the server is not writable by drupal
thanks
http://drupal.org/project/transliteration I think this module help me in my problem related this issue.
There's a known problem with Drupal 6.15 and IIS (see http://drupal.org/node/419734). If you're on 6.15, try backing down to 6.14 until a fix is completed.
I solved it. The rewrite module is not enabled on my IIS server, so I had to change a line of code inside the imagecache.module to add "index.php?q=
return url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);

Resources