'Problems when uploading image to server nginx php 7.4 UPLOAD_ERR_NO_TMP_DIR with same req

I'm trying to upload an image with postman to my server. The problem is that it sometimes works and sometimes it does not.

I'm using exactly the same request every time. Is this some kind of protection within nginx or php?

When it works:

 [image] => Array
        (
            [name] => 9.jpeg
            [type] => image/jpeg
            [tmp_name] => /home/test/tmp/php9LDwAL
            [error] => 0
            [size] => 351162
        )

When it fails:

[image] => Array
        (
            [name] => 9.jpeg
            [type] => 
            [tmp_name] => 
            [error] => 6
            [size] => 0
        )

PHP 7.4.29

edit 1: found some error logs:


File(/tmp) is not within the allowed path(s): (/home/test/web/site.com/public_html:
/home/test/tmp) in Unknown on line 0
[Fri May 20 19:56:02.661312 2022] [php7:warn] [pid 15995] PHP Warning:  
File upload error - unable to create a temporary file in Unknown on line 0

edit 2:

I think i found the problem. When uploading a file to the server it uses sometimes sys_temp_dir and sometimes upload_tmp_dir as upload_dir

i first changed sys_temp_dir to /home/test/tmp without luck. After changing it to /home/test/web/site.com/public_html/tmp/ it is now working, but still does not feel like a proper solution.

Can someone please explain why the upload occasionally uses different paths? sys_temp_dir / upload_tmp_dir



Solution 1:[1]

```
import pandas as pd
import xml.etree.ElementTree as ET


test_xml = '/Users/cole/PycharmProjects/Birds/VisualizeConvsTest/Robin.xml'

tree = ET.parse(test_xml)
root = tree.getroot()

labelimg_params = {}
#takes an empty dict and adds in the params as we recursively go through the xml file
def find_children(root, params):

    children = root.getchildren()
    for child in children:
        if child.getchildren():
            find_children(child, params)
        params[child.tag] = child.text
        #print(child.tag, child.text)
    return labelimg_params

xml_dict = find_children(root, labelimg_params)
df = pd.DataFrame([xml_dict])
print(df.columns.to_list())
bbox = df[['xmin', 'ymin', 'xmax', 'ymax']]
print(bbox)
```

['folder', 'filename', 'path', 'database', 'source', 'width', 'height', 'depth', 'size', 'segmented', 'name', 'pose', 'truncated', 'difficult', 'xmin', 'ymin', 'xmax', 'ymax', 'bndbox', 'object']

xmin ymin xmax ymax

0 87 104 501 375

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zoltasaur