Cannot refer to uploaded files

Just done an install, tried to upload a file and refer it to a page 'file:/test/image_21.png'
but I got 404 file:/test/image_21.png error message.


This my env

PHP 7.4.29 (cli) (built: Apr 12 2022 10:55:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with the ionCube PHP Loader + ionCube24 v11.0.1, Copyright (c) 2002-2022, by ionCube Ltd.
    with Zend OPcache v7.4.29, Copyright (c), by Zend Technologies	

Server version: Apache/2.4.6 (CentOS)
Server built:   Mar 24 2022 14:57:57	

Wackowiki version: 6.0.25	

Server version: 8.0.19 MySQL Community Server - GPL	

Any ideas?
thanks and regards

Comments

  1. Re: Cannot refer to uploaded files

    When you upload a file, the correct file: syntax is displayed in the filemeta handler. Normally, the relative path is sufficient. The absolute path is required only when you embed a local file attached to a page in another page.



    A 404 file:/test/image_21.png message indicates that either
    1. the path to the file is false
      • Please check if the file is already attached to the /test page.
      • Check if the page syntax is correct, the page tag is case sensitive.
      • Check if the image was uploaded as local file and not as global file (attached to a page / global name space)
        • test for file:image_21.png and file:/image_21.png
    2. the file upload failed
      • Is the file visible in the filemeta handler? (/test/attachments -> to page -> click on the image)
      • Could you see the image after the file upload?
    3. the file folder has insufficient access rights

    Please check the file/perpage/ and file/folder/ folder as well the file table in the database, if the uploaded file is there.

    Do you use mod_rewrite?
    • WikiAdmin
    • 13.05.2022 09:07 edited
  2. Re: Cannot refer to uploaded files

    Hi WikiAdmin,

    1. the path to the file is false --> The path is correct and has the right permission.
    • the file path is: file/perpage/@18@image_21.png

    https://i.ibb.co/k5Trrsr/screenshot-127.jpg

    https://i.ibb.co/sb5DxBs/screenshot-124.jpg

    https://i.ibb.co/KyMBGMf/screenshot-128.jpg


    2. the file upload failed --> Upload is succeded.
    • After upload a file, I got File upload successful but also File not found messages

    https://i.ibb.co/q9W1XzB/screenshot-125.jpg

    3. the file folder has insufficient access rights --> 'file/perpage' and 'file/global' have permission (I have tried full 777 permission)

    4. check the file/perpage/ and file/folder/ folder as well the file table in the database --> There are no data in the 'file' and 'file_link' tables.

    https://i.ibb.co/vDtcrTs/screenshot-126.jpg

    5. Do you use mod_rewrite --> I have tried both 'subdomain' and 'subdirectory'

    <VirtualHost 192.168.50.6:80>
        DocumentRoot /apps/testapp/wacko_test1/htdocs/
        ServerAlias wacko.kmb-note
        <Directory /apps/testapp/wacko_test1/htdocs/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>	


    and this

    Alias /wacko_test1/ "/apps/webapps/wacko_test1/htdocs/"
    Alias /wacko_test1 "/apps/webapps/wacko_test1/htdocs"
    
    <Directory "/apps/webapps/wacko_test1/htdocs">
    	Options Indexes FollowSymLinks
    	AllowOverride All
    	
    	<IfVersion < 2.3 >
    		Order allow,deny
    		Allow from all
    		Satisfy all
    	</IfVersion>
    	<IfVersion >= 2.3>
    		Require all granted
    	</IfVersion>
    </Directory>	


    and in the .htaccess (for subdir)
    <IfModule mod_rewrite.c>
    	<IfModule mod_env.c>
    		SetEnv HTTP_MOD_REWRITE on
    	</IfModule>
    	RewriteEngine on
    	RewriteBase /wacko_test1/
    	RewriteRule ^(index.php?.*)$ - [S=1]
        RewriteRule ^(.*)$ /wacko_test1/index.php?page=$1 [QSA,PT,L]
    </IfModule>	


    Thanks and regards
    • coffe1nk
    • 04.05.2022 13:31 edited
  3. Re: Cannot refer to uploaded files

    So it uploads the file but it did not write the corresponding data in the file table.
    The WackoFormatter parses then the file: link and can't find the corresponding record in the file table.
    Did you upgrade or downgrade the wiki? Please check if the file table has no missing or changed fields, this can happen if you changed the version without using the installer. The SQL script probably fails to insert the file record due to DB structure discrepancies.

    Please check the file table against the file table schema for your version.

    Fix the DB structure discrepancies by hand or run a fresh install with the version you want use. Additionally you can turn on the debug option, so it will show you all failed SQL queries in the footer, look out for -1.

    https://github.com/WackoWiki/w[...]page/upload.php#L267 (Example for WackoWiki 6.1)
    • WikiAdmin
    • 01.06.2022 10:13 edited
  4. Re: Cannot refer to uploaded files

    Hi WikiAdmin,

    did you upgrade or downgrade the wiki?
    > It's new fresh install 6.0.25.zip

    I created the database

    CREATE DATABASE wacko_test CHARACTER SET utf8mb4;
    GRANT ALL PRIVILEGES ON wacko_test.* TO 'apps'@'localhost' WITH GRANT OPTION;
    FLUSH PRIVILEGES;	


    and then followed the install instruction. there is no error except upload file.

    mysql> desc wacko_file;
    +------------------+------------------+------+-----+---------+----------------+
    | Field            | Type             | Null | Key | Default | Extra          |
    +------------------+------------------+------+-----+---------+----------------+
    | file_id          | int unsigned     | NO   | PRI | NULL    | auto_increment |
    | page_id          | int unsigned     | NO   | MUL | 0       |                |
    | user_id          | int unsigned     | NO   | MUL | 0       |                |
    | file_name        | varchar(255)     | NO   |     |         |                |
    | file_lang        | varchar(5)       | NO   |     |         |                |
    | file_description | varchar(255)     | NO   |     |         |                |
    | caption          | text             | NO   |     | NULL    |                |
    | author           | varchar(255)     | NO   |     |         |                |
    | source           | varchar(255)     | NO   |     |         |                |
    | source_url       | varchar(255)     | NO   |     |         |                |
    | license_id       | int unsigned     | NO   |     | 0       |                |
    | uploaded_dt      | datetime         | YES  |     | NULL    |                |
    | modified_dt      | datetime         | YES  |     | NULL    |                |
    | file_size        | int unsigned     | NO   |     | 0       |                |
    | picture_w        | int unsigned     | NO   |     | 0       |                |
    | picture_h        | int unsigned     | NO   |     | 0       |                |
    | file_ext         | varchar(10)      | NO   |     |         |                |
    | mime_type        | varchar(255)     | NO   |     |         |                |
    | deleted          | tinyint unsigned | YES  | MUL | 0       |                |
    +------------------+------------------+------+-----+---------+----------------+
    19 rows in set (0.00 sec)	


    mysql>  SHOW INDEX IN wacko_file;
    +------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
    | Table      | Non_unique | Key_name      | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
    +------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
    | wacko_file |          0 | PRIMARY       |            1 | file_id     | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          0 | idx_page_id   |            1 | page_id     | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          0 | idx_page_id   |            2 | file_name   | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          1 | idx_page_id_2 |            1 | page_id     | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          1 | idx_page_id_2 |            2 | uploaded_dt | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          1 | idx_deleted   |            1 | deleted     | A         |           0 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
    | wacko_file |          1 | idx_user_id   |            1 | user_id     | A         |           0 |     NULL |   NULL |      | BTREE      |         |               | YES     | NULL       |
    +------------+------------+---------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
    7 rows in set (0.39 sec)	


    I tried to enable debug mode const PHP_ERROR_REPORTING = 5

    and got this message in the /etc/httpd/logs/error_log

    [Wed May 04 21:35:01.943156 2022] [php7:notice] [pid 15986] [client 192.168.50.1:18791] PHP Notice:  Trying to access array offset on value of type null in /apps/testapp/wacko_test1/htdocs/handler/page/upload.php on line 298, referer: http://wacko.kmb-note/test?show_files=1
    [Wed May 04 21:35:01.943425 2022] [php7:notice] [pid 15986] [client 192.168.50.1:18791] PHP Notice:  Trying to access array offset on value of type null in /apps/testapp/wacko_test1/htdocs/handler/page/upload.php on line 310, referer: http://wacko.kmb-note/test?show_files=1	


    https://i.ibb.co/GdJhWdv/screenshot-129.jpg

    thanks and regards,
    • coffe1nk
    • 04.05.2022 14:40 edited
  5. Re: Cannot refer to uploaded files

    I did a local test with WackoWiki 6.0.30 and all works as expected.

    If you want find the error turn debugging on (including SQL queries, see system section in Admin panel) and comment out
    https://github.com/WackoWiki/w[...]page/upload.php#L309

    Comment out this line and read the SQL log for errors.
    # $this->http->redirect($this->href('filemeta', '', ['m' => 'show', 'file_id' => (int) $file['file_id']]));	


    Admin Panel -> System -> Debug mode
    debug and query caching option
    enable the debug option to show all executed SQL queries and disable the query caching option
    • WikiAdmin
    • 01.06.2022 10:14 edited
  6. Re: Cannot refer to uploaded files

    Hi WikiAdmin,

    This is the debug output:

    Program execution statistics
    
        Memory allocated: 4.00 MiB
        Overall time taken: 0.055 sec.
        Execution time: 0.052 sec.
        SQL time: 0.003 sec.
        SQL queries: 13
        SQL queries dump follows:
            SELECT p.*, u.user_name, o.user_name AS owner_name FROM wacko_page p LEFT JOIN wacko_user o ON (p.owner_id = o.user_id) LEFT JOIN wacko_user u ON (p.user_id = u.user_id) WHERE tag = 'test' LIMIT 1
            [0.0005 sec., 1 rows]
            SELECT c.category_id, c.category, c.category_lang FROM wacko_category c INNER JOIN wacko_category_assignment ca ON (c.category_id = ca.category_id) WHERE ca.object_id = 18 AND ca.object_type_id = 1
            [0.0002 sec., 0 rows]
            SELECT watch_id, comment_id, pending FROM wacko_watch WHERE user_id = 3 AND page_id = 18 LIMIT 1
            [0.0001 sec., 1 rows]
            SELECT file_id FROM wacko_file_link WHERE page_id IN (18)
            [0.0001 sec., 0 rows]
            SELECT to_page_id, to_tag FROM wacko_page_link WHERE from_page_id IN (18)
            [0.0001 sec., 0 rows]
            SELECT SUM(file_size) AS used_user_quota FROM wacko_file WHERE user_id = 3 LIMIT 1
            [0.0005 sec., 1 rows]
            SELECT SUM(file_size) AS used_quota FROM wacko_file LIMIT 1
            [0.0004 sec., 1 rows]
            INSERT INTO wacko_file SET page_id = 18, user_id = 3,file_name = 'image_210.png', file_lang = 'en', file_description = '', file_size = 146011,picture_w = 1600,picture_h = 1030,file_ext = 'png',mime_type = 'image/png',uploaded_dt = '2022-05-04 15:00:41',modified_dt = UTC_TIMESTAMP()
            [0.0002 sec., -1 rows]
            SELECT COUNT(file_id) AS n FROM wacko_file WHERE 1=1 AND page_id = 18 AND deleted <> 1 LIMIT 1
            [0.0002 sec., 1 rows]
            UPDATE wacko_page SET files = 0 WHERE page_id = 18 LIMIT 1
            [0.0002 sec., 0 rows]
            SELECT COUNT(file_id) AS n FROM wacko_file WHERE 1=1 AND user_id = 3 AND deleted <> 1 LIMIT 1
            [0.0002 sec., 1 rows]
            UPDATE wacko_user SET total_uploads = 0 WHERE user_id = 3 LIMIT 1
            [0.0001 sec., 0 rows]
            SELECT file_id FROM wacko_file WHERE file_name = 'image_210.png' AND page_id = 18 LIMIT 1
            [0.0001 sec., 0 rows]
    
    Language data
    
        Multilanguage: false
        HTTP_ACCEPT_LANGUAGE set: true
        HTTP_ACCEPT_LANGUAGE value: en-US,en;q=0.5
        User agent language: en
        User language set: true
        User language value: en
        Page language: en
        Config language: en
        User selected language: en
        Charset: utf-8
        HTML Entities Charset: UTF-8
    
    MySQL character set
    
        character_set_client: utf8mb4
        character_set_connection: utf8mb4
        character_set_database: utf8mb4
        character_set_filesystem: binary
        character_set_results: utf8mb4
        character_set_server: utf8mb4
        character_set_system: utf8
        collation_connection: utf8mb4_unicode_520_ci
    
    SQL mode set
    
        GLOBAL: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
        SESSION: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
    
    Session data
    
        session_id(): 7613U41sIKPPTCyhSXB5m
        Base URL: http://wacko.kmb-note/
        Rewrite Mode: on
        HTTP_MOD_ENV: on
        HTTP_MOD_REWRITE: on
        HTTPS: off
        IP-address: 0.0.0.0
        SERVER_PORT: 80
        TLS: on
        TLS implicit: off
        Cookie path: /	


    I did a local test with WackoWiki 6.0.30 and all works as expected.

    I have tried 6.0.30 too, but the installation stopped before creating tables. I think I will create another thread for this problem.
    • coffe1nk
    • 04.05.2022 15:01 edited
  7. Re: Cannot refer to uploaded files

    The culprit: [0.0003 sec., -1 rows] as expected
    INSERT INTO wacko_file SET page_id = 18, user_id = 3,file_name = 'image_28.png', file_lang = 'en', file_description = '', file_size = 146011,picture_w = 1600,picture_h = 1030,file_ext = 'png',mime_type = 'image/png',uploaded_dt = '2022-05-04 14:52:29',modified_dt = UTC_TIMESTAMP()
            [0.0003 sec., -1 rows]	


    Put the query as is for example in phpMyAdmin and it will tell you what is missing or wrong. And please upgrade to 6.0.30.

    This is the output of my test with WackoWiki 6.0.30:
    INSERT INTO test_file SET page_id = 2, user_id = 3,file_name = 'ap_system_settings_debug_en.png', file_lang = 'en', file_description = 'debug options', file_size = 40897,picture_w = 1807,picture_h = 727,file_ext = 'png',mime_type = 'image/png',uploaded_dt = '2022-05-04 15:07:10',modified_dt = UTC_TIMESTAMP()
    [0.0018 sec., 1 rows]	

    • WikiAdmin
    • 04.05.2022 15:23 edited
  8. Re: Cannot refer to uploaded files

    Hi WikiAdmin

    This is the error

    Field 'caption' doesn't have a default value	


    I changed the default value

    ALTER TABLE wacko_file CHANGE caption caption text DEFAULT NULL;	


    and it works..... YEAAA.....

    https://i.ibb.co/rmLrXLV/screenshot-130.jpg

    Thanks WikiAdmin
    • coffe1nk
    • 04.05.2022 15:27 edited
  9. Re: Cannot refer to uploaded files

    This can be, if you run with SQL Strict mode. We should fix this, so it will run out of the box with SQL strict mode.

    constants.php
    const SQL_MODE_STRICT				= 'TRADITIONAL,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY';
    const SQL_MODE_PERMISSIVE			= 'NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER';	


    config.php
    'sql_mode_strict' => '0',	


    Can you please provide a patch.
    • WikiAdmin
    • 11.05.2022 07:45 edited
  10. Re: Cannot refer to uploaded files

    Thank You WikiAdmin,

    I have tried

    const SQL_MODE_STRICT				= 'TRADITIONAL,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY';
    const SQL_MODE_PERMISSIVE			= 'NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER';
    
    //these two parameters are default value	


    and config.php already set to

    'sql_mode_strict' => '0',	


    change back

    ALTER TABLE wacko_file MODIFY caption text NOT NULL;	


    The result is :

    INSERT INTO wacko_file SET page_id = 18, user_id = 3,file_name = '16487410983501.jpg', file_lang = 'en', file_description = '', file_size = 46871,picture_w = 800,picture_h = 800,file_ext = 'jpg',mime_type = 'image/jpeg',uploaded_dt = '2022-05-04 15:44:13',modified_dt = UTC_TIMESTAMP()
    [0.0002 sec., -1 rows]	




    wacko/setup/database_mysql.php

    $tbl_file =
    	"CREATE TABLE {$pref}file (
    		file_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    		page_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		user_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		file_name VARCHAR(255) NOT NULL DEFAULT '',
    		file_lang VARCHAR(5) NOT NULL DEFAULT '',
    		file_description VARCHAR(255) NOT NULL DEFAULT '',
    		-- caption TEXT NOT NULL, <<=== change to:
    		caption TEXT,
    		author VARCHAR(255) NOT NULL DEFAULT '',
    		source VARCHAR(255) NOT NULL DEFAULT '',
    		source_url VARCHAR(255) NOT NULL DEFAULT '',
    		license_id INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		uploaded_dt DATETIME NULL DEFAULT NULL,
    		modified_dt DATETIME NULL DEFAULT NULL,
    		file_size INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		picture_w INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		picture_h INT(10) UNSIGNED NOT NULL DEFAULT '0',
    		file_ext VARCHAR(10) NOT NULL DEFAULT '',
    		mime_type VARCHAR(255) NOT NULL DEFAULT '',
    		deleted TINYINT(1) UNSIGNED NULL DEFAULT '0',
    		PRIMARY KEY (file_id),
    		UNIQUE idx_page_id (page_id, file_name),
    		KEY idx_page_id_2 (page_id, uploaded_dt),
    		KEY idx_deleted (deleted),
    		KEY idx_user_id (user_id)
    	) {$engine} COMMENT='' {$charset} {$collation}";	

    • coffe1nk
    • 04.05.2022 17:33 edited
Log in or create an account to post a comment.