Codeigniter Linux无法打开流:在777模式临时目录中创建图像文件/qr代码的权限被拒绝

63lcw9qa  于 2023-01-10  发布在  Linux
关注(0)|答案(1)|浏览(178)

请帮助我。我试图通过嵌入来自/var/www/assets/images的图像,使用phpqrcode库在/var/www/html/temp文件夹中创建一个临时PNG图像文件/QR代码。但它一直显示如下错误:

A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagepng(/var/www/html/temp/10012023_053321_pm_qrcode.png): failed to open stream: Permission denied</p>
<p>Filename: phpqrcode/qrimage.php</p>
<p>Line Number: 43</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/libraries/phpqrcode/qrimage.php<br />
            Line: 43<br />
            Function: imagepng          </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/libraries/phpqrcode/qrencode.php<br />
            Line: 494<br />
            Function: png           </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/libraries/phpqrcode/qrencode.php<br />
            Line: 286<br />
            Function: encodePNG         </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 145<br />
            Function: png           </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagecreatefrompng(/var/www/html/temp/10012023_053321_pm_qrcode.png): failed to open stream: No such file or directory</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 149</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 149<br />
            Function: imagecreatefrompng            </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagesx() expects parameter 1 to be resource, bool given</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 158</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 158<br />
            Function: imagesx           </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagesy() expects parameter 1 to be resource, bool given</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 159</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 159<br />
            Function: imagesy           </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Division by zero</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 166</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 166<br />
            Function: _error_handler            </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagecopyresampled() expects parameter 1 to be resource, bool given</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 169</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 169<br />
            Function: imagecopyresampled            </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

        
    

</div>
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  imagepng() expects parameter 1 to be resource, bool given</p>
<p>Filename: helpers/portalsdm_helper.php</p>
<p>Line Number: 172</p>

    <p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/helpers/portalsdm_helper.php<br />
            Line: 172<br />
            Function: imagepng          </p>

        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/application/controllers/Sestama.php<br />
            Line: 465<br />
            Function: create_qr         </p>

        
    
        
    
        
            <p style="margin-left:10px">
            File: /var/www/html/index.php<br />
            Line: 315<br />
            Function: require_once          </p>

我已经将/var/www/html/temp和/var/www/assets/images目录模式设置为777,并将所有者和组设置为apache。如果有帮助,我使用的是Codeigniter 3、Linux Centos 9和Apache。这也是导致上述错误的实际脚本:

require_once APPPATH . "libraries/phpqrcode/qrlib.php";
    $tempdir = FCPATH . "temp/"; //Nama folder tempat menyimpan file qrcode
    if (!file_exists($tempdir)) //Buat folder bername temp
        mkdir($tempdir);

    //ambil logo
    $logopath = base_url() . "assets/images/Logo-BMKG-new-242x300.png";

    //isi qrcode jika di scan
    $codeContents = $content;
    $filename = date('dmY_his_a', time()) . '_' . $suffix . '.png';
    //simpan file qrcode
    QRcode::png($codeContents, $tempdir . strval($filename), QR_ECLEVEL_H, 10, 4);

    // ambil file qrcode
    $QR = imagecreatefrompng($tempdir . $filename);

    // memulai menggambar logo dalam file qrcode
    $logo = imagecreatefromstring(file_get_contents($logopath));

    imagecolortransparent($logo, imagecolorallocatealpha($logo, 0, 0, 0, 127));
    imagealphablending($logo, false);
    imagesavealpha($logo, true);

    $QR_width = imagesx($QR);
    $QR_height = imagesy($QR);

    $logo_width = imagesx($logo);
    $logo_height = imagesy($logo);

    // Scale logo to fit in the QR Code
    $logo_qr_width = $QR_width / 8;
    $scale = $logo_width / $logo_qr_width;
    $logo_qr_height = $logo_height / $scale;

    imagecopyresampled($QR, $logo, $QR_width / 2.3, $QR_height / 2.3, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);

    // Simpan kode QR lagi, dengan logo di atasnya
    imagepng($QR, $tempdir . $filename);
    return [base_url() . '/' . $tempdir . $filename, $tempdir . $filename];

$contentFCPATH . "/uploads/mutasi/beritaacara/" . $data['title_pdf']。请帮助我我做错了什么?我如何使它工作?它说这是一个权限问题,但我已经尝试将几乎任何相关的目录模式设置为777,将其所有者和组设置为Apache,但仍然不起作用。

qc6wkl3g

qc6wkl3g1#

结果发现我的SELinux是启用的,它处于强制模式,我的临时文件夹上下文是unconfined_u:object_r:httpd_sys_content_t:s0。当我使用chcon -R -t httpd_sys_rw_content_t temp将临时文件夹上下文设置为httpd_sys_rw_content_t时,问题就解决了。谢谢大家。

相关问题