Apache上载路径不可写

时间:2017-11-07 18:15:52

标签: php apache

我在RedHat服务器上运行Apache / 2.4.6服务器。我正在/var/www/html/中的weber服务器的根目录运行一个苗条的应用程序。

我想上传并映像并将其保存到指定的文件夹中。我可以在我的本地apache环境中完美地运行应用程序。

这是我的简单控制器功能:

public function test($request, $response, $args)
{

$files = $request->getUploadedFiles();


if (empty($files['file'])) 
    return $response->withJson(['message' => 'Could not find file'])->withStatus(400); 

$file = $files['file'];
$fileName = $file->getClientFilename();

//app and images folder both ahve 777 permissions
$file->moveTo('/var/www/html/app/images/{$fileName}');

return $response->withStatus(200)->write('Test Method');

} 

我可以回显文件名并看到它就在那里它只是移动文件我得到不可写的路径。我不明白为什么。

1 个答案:

答案 0 :(得分:0)

这是由RedHat激活的SEL(安全增强型Linux)引起的问题。显然,无论文件夹权限如何,SEL都不允许上传到任何目的地,您必须手动允许。我终于可以使用以下命令上传:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Windows;
using System.Windows.Forms;
using System.Globalization;
using System.Runtime.Versioning;
using System.Threading;

namespace DataImportServices
{
    public class ExcelImport : IDataImport
    {
        public DataTable ImportData(OpenFileDialog openFile)
        {
            var dataTable = new DataTable();

            string query;
            var hasHeaders = false;
            var HDR = hasHeaders ? "Yes" : "No";
            string connectionString;

            if (openFile.FileName.Substring(openFile.FileName.LastIndexOf(".")).ToLower() == ".xlsx")
            {
                connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + openFile.FileName + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
            }
            else
            {
                connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFile.FileName + ";Extended Properties=\"Excel 8.0;HDR=" + HDR + ";IMEX=0\"";
            }

            using (OleDbConnection cn = new OleDbConnection(connectionString))
            {
                cn.Open();
                DataTable schemaTable = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                DataRow schemaRow = schemaTable.Rows[0];
                string sheet = schemaRow["TABLE_NAME"].ToString();

                if (!sheet.EndsWith("_"))
                {
                    query = "SELECT * FROM [" + openFile.FileName + "]";
                    using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, cn))
                    {
                         dataTable.Locale = CultureInfo.CurrentCulture;
                         dataAdapter.Fill(dataTable); //The error occurs here with a "" is not an acceptable. If I put a name ie "Data" it says its not an adorecord.
                    }
                }                
            }
            return (dataTable);
        }
    }
}

我对SEL知之甚少,所以遗憾的是除了这个解决方案对我有用之外无法添加更多细节。

相关问题