G
G
Gleb Tregubov2018-10-04 15:37:02
PHP
Gleb Tregubov, 2018-10-04 15:37:02

How to correctly transfer files from the database to the file system?

Outputting files from the database to the file system
Dear sirs, good afternoon!
There was a problem with the output of files from the PostgreSQL database to the file system on the production server. There is a code that works locally on my computer, on which MAMP is installed. The meaning of this code is to select data from the database, place the data in the file system directory, then send these files to a remote server (send using the php cURL library). On a combat server with a different OS, these manipulations do not work, the code stops at fetching files from the database and placing them in the file system.
Local OS: MacOS 10.14.1 MAMP Version: 4.5 Web Server: Apache/2.2.34 (Unix) PHP Version: 7.2.1
Combat OS: Debian GNU/Linux 9.4 (stretch) Web Server: Apache/2.4. 25 (Debian) PHP version: 7.0.30-0+deb9u1
When outputting files on the combat server from the database, the following errors occur:
The contents of the file are sent incorrectly - the file arrives in the file system broken, the file size is either zero or 1KB.
The file name is transmitted incompletely, on some character it is cut. (PR: “prezentatsiya_1128329_435”, “prezentatsiya_1128329_Д). The character type does not depend on a number or a letter. The name of the files comes from the database already translated into transliteration. (I did a translation from Russian to Latin using PHP, but this did not help, so we did the transliteration in the database)
I assumed that there was some problem with the locale on Debian 9 and took the following steps:

1. export LANGUAGE=ru_RU.UTF-8
2. export LANG=ru_RU.UTF-8
3. export LC_ALL=ru_RU.UTF-8
4. locale-gen ru_RU.UTF-8
5. apt-get install --reinstall locales
6. dpkg-reconfigure locales

They work for the duration of the terminal session, on MacOS the OS was English, for the duration of the terminal session the language switched to Russian, but when reconnecting to the server through the terminal, the locale settings were reset; the dpkg-reconfigure locales command did not affect the display of the command line interface. Changing the language on MacOS to Russian helped in displaying the Russian language in the terminal, but nothing more.
After applying these settings, the locale command shows the following results:
LANG=ru_RU.UTF-8
LANGUAGE=
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
LC_TIME="ru_RU.UTF-8"
LC_COLLATE="ru_RU.UTF-8"
LC_MONETARY="ru_RU.UTF-8"
LC_MESSAGES="ru_RU.UTF-8"
LC_PAPER="ru_RU.UTF-8"
LC_NAME="ru_RU.UTF-8"
LC_ADDRESS="ru_RU.UTF-8"
LC_TELEPHONE="ru_RU.UTF-8"
LC_MEASUREMENT="ru_RU.UTF-8"
LC_IDENTIFICATION="ru_RU.UTF-8"
LC_ALL=

I assume that, after all, the matter is in the locale settings, so I do not attach the working code, if necessary, I will add it.
I was looking for information on setting up the locale on Debian, I took the instructions in this source, the Standard item, performed the following steps:
1. Edited the /etc/default/locale file, adding the line LANG=ru_RU.UTF-8
2. Rebooted the server.
3. Did not help
4. Looked at the /etc/locale.gen file
5. After applying the dpkg-reconfigure locales command, the following lines "en_US.UTF-8 UTF-8", "ru_RU.UTF-8 UTF-8" are uncommented
6. Not helped
Rules php.ini file - increased the size of sent files:
upload_max_filesize = 30M
Sending files is allowed, directive value:
file_uploads = On
Post_max_size setting value:
post_max_size = 8M
Tell me, what could be the reason for this problem? Where is the dog buried? There is not enough experience to independently determine in which direction to move to solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2018-10-05
@2ord

The contents of the file are sent incorrectly - the file comes to the file system broken, the file size is either zero or 1KB.
It is worth checking that the files are indeed stored intact in the DBMS by checking their size through the PostgreSQL client.
BYTEA stores octets of data, including \0, which, in the case of strings, is interpreted as the end of a line. That is, the data must be stored in Python in a structure corresponding to a byte array.
The file name is incomplete
Then make sure the PHP program uses a variable of the appropriate size to store the filename.

G
Gleb Tregubov, 2018-10-10
@sollerij

Now I hang try / catch on all parts of the code. Perhaps this will somehow help in detecting errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question