File upload from server failed

File upload from server failed

jalapejalape Posts: 114Questions: 1Answers: 1

Hello,
I have a problem loading image files. In localhost it works perfectly, but not when uploading it to the server.

When trying to upload, I get an error “A server error occurred while uploading the file”
In the database, the writing of all the fields seems correct, except the field "system_path", which writes a rather strange path:
/var/www/vhost/javierlasen.es/home/html/uploads/1.jpg
When the correct path in the browser would be:
https;//www.javierlasen.es/mapas/uploads/1.jpg
and physically the image would have to be saved on the server in the path:
html/mapas/uploads/1.jpg

Thanks

Replies

  • allanallan Posts: 54,900Questions: 1Answers: 8,605 Site admin

    /var/www/vhost/javierlasen.es/home/html/uploads/1.jpg

    That’s the file system path (equivalent of C:\ if you are a windows user).

    https;//www.javierlasen.es/mapas/uploads/1.jpg

    That’s the web accessible path. You’ll need both paths throughout the lifetime of the file on the server.

    It looks like you might just be missing the mapas part from your system path. Can you show me how you have configured the upload code please?

    Allan

  • jalapejalape Posts: 114Questions: 1Answers: 1

    Thanks Allan for answering,

    The field corresponding to the image in the editor looks like this:

                    {
                        label: "Imágenes:",
                        name: "imagen_tb[].id",
                        type: "uploadMany",
                        display: function ( fileId, counter ) {
                            return '<img src="'+editor.file( 'imagen_tb', fileId ).web_path+'"/>';
                        },
                        noFileText: 'No images'
                    } 
    

    The data is collected from the database, in this way:

    ->join(
        Mjoin::inst( 'imagen_tb' )
        ->link( 'sml_markers.id', 'marker_imagen.marker_id' )
        ->link( 'imagen_tb.id', 'marker_imagen.imagen_id' )
        ->fields(
            Field::inst( 'id' )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/__ID__.__EXTN__' )
            //->upload( Upload::inst( 'https://www.javierlasen.es/mapas'.'/uploads/__ID__.__EXTN__' )
            //->upload( Upload::inst( dirname(__FILE__).'/uploads/__ID__.__EXTN__' )
                ->db( 'imagen_tb', '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( 7000000, 'Los archivos deben tener un tamaño inferior a 7MB ' ) )
                ->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Sube una imagen " ) )
            )
        )
    )
    
  • jalapejalape Posts: 114Questions: 1Answers: 1

    Indeed, adding "maps" works perfectly.

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

    What I still do not understand is that it does not point to a type route: https: // www ...

  • allanallan Posts: 54,900Questions: 1Answers: 8,605 Site admin

    Because www.whatever could be anywhere on your server.

    The way the web-server you are using works is that it will define a webroot - in your case that will be /var/www/vhost/javierlasen.es/home/html/ (and can be accessed in PHP as $_SERVER['DOCUMENT_ROOT']).

    That means that any file under that system path can be accessed from the web. If something was at /var/www/vhost/javierlasen.es/home/html/datatables.html then you could use javierlasen.es/datatables.html for example.

    Generally with PHP URL paths will map directly to the system paths. You just need to know the web root to complete the mapping.

    Hope that helps.

    Allan

  • jalapejalape Posts: 114Questions: 1Answers: 1

    A lot.
    Thank you very much for the help and the explication.

Sign In or Register to comment.