PHP Large File Uploads (again) - iis-7

Firstly sorry for another of the same (countless iterations of this question I know), but I'm completely stoomped on this one and spent all day looking for answers (along with checking all the previous threads here).
So Im trying to upload large(ish) files through PHP. The script fails at files around 8-10Mb mark (works for files upto 7.5Mb, fails at 10Mb). It just returns an empty file array, ie:
print_r($_FILES)
= array( )
Im running IIS7, using Plesk 10, on a Windows 2008 R2 OS. Heres my form:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="200000000">
<input name="Filedata" type="file" />
<input type="submit" value="Upload File" class="button" />
</form>
Some relevant php.ini variables:
max_execution_time: 240
max_input_time: 360
post_max_size: 1600M
upload_max_filesize: 800M
memory_limit 1600M
And my web.config has this in:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="200000000"/>
</requestFiltering>
</security>
I know that the php.ini's are being listened to, because php_info() reports them as that (also ini_get('...') reports them as correct as well. As an aside they are the 'local' values, the 'master' ones are lot lower (but am assuming if php_info() reports the local as that then they are the ones being used). I put in some debug code to my script:
echo ini_get('post_max_size') . "<br />";
echo ini_get('upload_max_filesize') . "<br />";
echo $_SERVER['CONTENT_LENGTH'] . "<br />";
That echos out:
1600M
800M
10424520
The last one is the 10Mb (ish) file size in bytes (I am assuming). So my question is, what am I missing here?

So I've finally found the answer here, and thought it may help some souls in the future.
It turns out that Plesk, although allowing you to overwrite the 'local' php settings, doesn't actually listen to the change, and the 'Master' values in the php.ini are being listened to, and the local ones aren't.
Theres more info here:
PHP post_max_size local value overridden by master value on Plesk / IIS?
To solve, I changed over the master values by changing the default plesk php.ini's as needed. phpinfo() reported my required post_max_size was now 800M in both local and master, and it worked as needed.

Related

NXLog always forward file on disk (even if it hasn't change)

I have the following NXLog config that reads a file from disk and forwards it to another host (syslog). By default, it appears NXLog only forwards the data in the log file if it has changed.
How can you configure 'nxlog.conf' so that it always forwards the file, even if the data is the same?
<Input in>
Module im_file
File "C:\\myfile.txt"
</Input>
<Output out>
Module om_tcp
Host 127.0.0.1
Port 12345
</Output>
<Route 1>
Path in => out
</Route>
After some digging on the NXLog forum, this cannot be done. Basically, NXLog will monitor the file (you can configure the frequency) for changes and re-transmit when it has appended values (or changed).
So, a workaround would be to delete the file and re-write the contents (on some schedule perhaps) to get NXLog to forward it again.
NXLog won't re-read data from a file unless that file is updated while nxlog is running.
There is another workaround however.
Add the ReadFromLast FALSE and SavePos FALSE to the im_file module definition and then periodically run nxlog -c <custom config>
The custom config will have to specify a different pid location though.

call Telegram.api in browser (Windows): sendPhoto

I am using Telegram to send pictures from a IP-cam.
This can be done on raspberry-PI like this:
curl -s -X POST "https://api.telegram.org/bot123456789:yourcode/sendPhoto" -F chat_id=123456789 -F photo="#/volume1/Data/temp/picture.jpeg"
Explanation: the picture is in the folder "/volume1/Data/temp" the name is "picture.jpeg"
I want to do the same on Windows and I constantly get message "{"ok":false,"error_code":400,"description":"Bad Request: Wrong persistent file_id specified: contains wrong characters or has wrong length"}"
This is exactly (exact for the bot and yourcode and chatid) what I transmit in the address of Google Chrome:
https://api.telegram.org/bot123456789:yourcode/sendPhoto?chat_id=123456789&photo="#C:/temp/picture.jpeg"
I can assure you the is no problem with autorisation (filling in file:///C:/temp/picture.jpeg in the browser shows me the picture).
And I have tried al kinds of variantions (with and without #, with and without ", etc. etc.). I cannot get it working.
And it works with sending text:
...../sendMessage?chat_id=123456789&text=”hello”
result is that I get the message "hello" and this in the browser: {"ok":true,"result":{"message_id" ......
I am sure I am close but do not know how to define exactly the "picture".
So the questions is: what is the exact way to transmit a picture with Telegram through a Windows browser using api.telegram.org? Please provide an example that is working.
Thanks in advance for help!
When you transmit that url in chrome (or any other browser) you are actually using "GET" method than can be used for send image with its "file_id".
But when you want to upload a file from your pc, you should use "POST" method to send it.
On of easiest ways is using a HTML form.
For an example:
<form action="https://api.telegram.org/bot2222222:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="11111111" />
<input type="file" name="photo" />
<input type="submit" value="send" />
</form>
Edit:
Also if you want to do it from command line you can use windows version of cUrl. You can download it from this link:
Windows cUrl
or use Invoke-RestMethod in windows powershell.
example command:
Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "multipart/form-data"

PHP - Cannot read uploaded temporary file

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.

Displaying images stored in Openshift server

I want to display image stored in Openshift server using img tag. Now, I have created a folder in $OPENSHIFT_DATA_DIR in the server. After going into the directory, I pwd to get the complete path :
/var/lib/openshift/52002234335h7b0000163/app-root/data/pamphlets
So, I specified the path in img tag as
<img src="/var/lib/openshift/52002234335h7b0000163/approot/data/pamphlets/1.png" class="map" alt="Image Not Available"
I even tried out
file:///var/lib/openshift/52002234335h7b0000163/app-root/data/pamphlets/1.png
but nothing is working. Can anyone point me out what is the mistake I am making?
I asume you are developing a web application. In that case you are missing the fact that you should use the path defined on the web server's DocumentRoot. Then you should use that as the root for your web-accessible files. So, for instance /pamphlets/ will be the path if your webserver's documentRoot points to $OPENSHIFT_DATA_DIR. If you are using one of the preloaded cartridges make sure that happens first.
Replace your code:
<img src="/var/lib/openshift/52002234335h7b0000163/approot/data/pamphlets/1.png" class="map" alt="Image Not Available" />
To:
<img src="/pamphlets/1.png" class="map" alt="Image Not Available" />
You don't need $OPENSHIFT_DATA_DIR => /var/lib/openshift/52002234335h7b0000163/approot/data/
I have never used jboss before but the basic method is saving your files in your project folder and then symlink to the Openshift data directory.

How to/can not set php.ini values in run time using ini_set() method?

I am using nginx as web server and when I do phpinfo(); it uses /etc/php5/fpm/php.ini
Now in my php code I am trying to set file upload size and max file uploads using following code.
ini_set('max_file_uploads', "50");
ini_set('upload_max_filesize', '250M');
But when I do ini_get('max_file_uploads') and echo the value it shows the default value as 20, infact I am not able to change any of the ini values in run time using ini_set().
Any ideas on how to change these values in run time using php code?
Thanks.
Not all PHP ini directives can be changed at runtime (via ini_set). See the file uploads section of the PHP manual and the definition of the changeability values, which are PHP_INI_SYSTEM and PHP_INI_PERDIR for your desired settings, neither of which can be set at runtime.
To get these settings in only one part of your app, you'll likely need to compromise and set max_file_uploads setting globally in your php.ini file (since it is PHP_INI_SYSTEM), and then use your favorite per-directory config mechanism (.htaccess, .user.ini (in >5.3), etc) to set upload_max_filesize for that particular part of your app. See here for good instructions.

Resources