在PHP中忽略设置upload_tmp_dir

时间:2018-02-22 16:41:55

标签: php nginx file-upload fpm

我试图通过nginx / php-fpm(php 7)上传文件

我不想上传要在tmp中上传的文件(在移动之前),所以我将upload_tmp_dir更改为指向另一个目录:

namespace MassInventoryItemImageUpload
{
    class Program
    {
        static void Main(string[] args)
        {
            //List of inventory Item CD's and associated file to upload.
            List<Tuple<string, string>> itemsToUpdate = new List<Tuple<string, string>>() { new Tuple<string, string>("InventoryItemCD", @"fileUrl") };

            Console.WriteLine("Updateing : " + itemsToUpdate.Count + " Inventory Items, press enter to begin");
            Console.ReadLine();

            AcumaticaProcessor processor = new AcumaticaProcessor();
            processor.Login();
            processor.UploadImages(itemsToUpdate);

            Console.WriteLine("Updates complete, press enter to exit program");
            Console.ReadLine();
        }
    }

    public class AcumaticaProcessor
    {
        DefaultSoapClient client = new DefaultSoapClient();

        public void Login()
        {
            client.Login("username", "password", "Company", "branch", null);
        }

        public void UploadImages(List<Tuple<string, string>> updateItems)
        {
            //Foreach Inventory Item in the list we are going to upload a files
            foreach(Tuple<string,string> updateItem in updateItems)
            {
                UploadImage(updateItem);
            }
        }

        private void UploadImage(Tuple<string, string> updateItem)
        {
            try
            {
                //Finds the StockItem with the given InventoryCD
                StockItem itemToUpdate = new StockItem()
                {
                    InventoryID = new StringSearch() { Value = updateItem.Item1 }
                };
                itemToUpdate = client.Get(itemToUpdate) as StockItem;

                //Updates found StockItem to include associated files
                client.PutFiles(itemToUpdate, FileData(updateItem.Item2));
            }
            catch(Exception e)
            {

            }
        }

        //Creates Acumatica File object from filestream and return File[] for uplaod 
        private Acumatica.File[] FileData(string url)
        {
            byte[] fileData;
            using (FileStream file = System.IO.File.Open(url, System.IO.FileMode.Open))
            {
                fileData = new byte[file.Length];
                file.Read(fileData, 0, fileData.Length);
            }
            return new Acumatica.File[1] { new Acumatica.File() { Name = url.Substring(url.LastIndexOf('\\') + 1), Content = fileData } };
        } 
    }
}

问题是文件仍然上传到/ tmp

我在我的虚拟主机中设置新值

/media/test/tmpUpload

要检查设置,在我的php上传脚本中,我在这里添加了以下调试代码

location ~ ^/(app|app_dev|config)\.php(/|$) {
    #other parameters
    fastcgi_pass unix:/var/run/php72-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param   SERVER_NAME         $host;
    fastcgi_param PHP_VALUE "short_open_tag=Off

    post_max_size = 400M
    upload_max_filesize = 400M
    upload_tmp_dir = /media/test/tmpUpload
    ";
}

echo ini_get('upload_tmp_dir');

以上是上传文件时的输出

var_dump($_FILES['file']);

所以PHP知道设置,但似乎忽略它。我错过了什么吗?

0 个答案:

没有答案