I want to modify and replace the upload image path

I want to modify and replace the upload image path

lancwplancwp Posts: 85Questions: 18Answers: 1
      ->setFormatter( Format::ifEmpty( null ) )
       //  ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
               ->upload( Upload::inst('//192.168.0.7'.'/uploads/__ID__.__EXTN__' )
                    ->db( 'files', 'id', array(
                        'filename'    => Upload::DB_FILE_NAME,
                        'filesize'    => Upload::DB_FILE_SIZE,
                        'web_path'    => Upload::DB_WEB_PATH,
                        'system_path' => Upload::DB_SYSTEM_PATH
                    ) )
                    ->validator( Validate::fileSize( 500000, '图片大小不能超过500K' ) )
                    ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
                ),

I use to upload pictures. My pictures are stored under 192.168.0.7 and uploaded on the web database_ The storage path under path is: \ \ 192.168.0.7 \ upload \ 42.jpg, but I want to add 8098 after \ \ 10.0.8.9 ,and use substr_ Replace function is replaced with "\ \ 192.168.0.7:8098 \ upload \ 42. JPG". How do I rewrite this code?

Thanks

Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    It sounds like you'd need to provide a custom upload action.

    Allan

  • lancwplancwp Posts: 85Questions: 18Answers: 1
    Field::inst( 'hppic' )
    ->upload(
        Upload::inst( function ( $file, $id ) {
            move_uploaded_file( $file['tmp_name'], '/uploads/'.$id );
            return $id;
        } )
            ->db( 'files', 'id', array(
                'fileName' => Upload::DB_FILE_NAME,
                'fileSize' => Upload::DB_FILE_SIZE
            ) )
    )
            ->setFormatter( 'Format::nullEmpty' ),
    

    Thanks allan
    Yes, I started to upload with customization, but according to the example, the above code reports an upload error. I don't think it can store the web_ Path and system_ Path, how do I put the web_ Path and system_ Web path is stored in the files table of the database_ Path and system_ Path field。

  • lancwplancwp Posts: 85Questions: 18Answers: 1

    Report: failed to load resource: the server responded with a status of 404 (not found)

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Your function there is the same as if you were to do:

    ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__' ) )
    

    And that would then allow Editor to use its system and web path parameters.

    Allan

  • lancwplancwp Posts: 85Questions: 18Answers: 1

    It can be executed normally and uploaded without customization

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Sorry - I'm not sure if that is a question, or an acknowledgement that the problem is now resolved with my last reply?

    Allan

  • lancwplancwp Posts: 85Questions: 18Answers: 1
    edited August 2021
        Field::inst( 'hppic' )
        ->upload(
            Upload::inst( function ( $file, $id ) {
    //          echo $_file["tmp_name"];
                move_uploaded_file( $file['tmp_name'], '/uploads');
                return $id;
            } )
                ->db( 'files', 'id', array(
                    'fileName' => Upload::DB_FILE_NAME,
                    'fileSize' => Upload::DB_FILE_SIZE,
                    'web_path' => '',
                        'system_path' => ''
    
                ) )
        )
                ->setFormatter( 'Format::nullEmpty' ),
    

    Allan,problem hasn't been solved yet. According to what you said, I want to use custom upload. At present, the code is as above, and there is no error, but the file hasn't been uploaded, and I don't know how to store the image path 'web_path' => '',
    'system_path' => '' to files table, But fileName and filesize field already stored

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    If you want to use a custom upload action, you will need to update the database with the path information in that action function. For example:

    $db->update(
      'files',
      [
        'webPath' => ...,
        'systemPath' => ...
      ],
      [
        'id' => $id
      ]
    );
    

    Remember to add use($db) to your anonymous function.

    Allan

  • lancwplancwp Posts: 85Questions: 18Answers: 1

    Thanks,

Sign In or Register to comment.