Requests for sub-resources using ftp protocols are obsolete

0

Good, I have the following problem:

when entering the product module of my platform (with HTTPS protocol) and consult a product, the information returned by the web service is the product detail, in which comes a field called image which has the ftp path of the image

" ftp: // user: password@domain/ruta/imagen.png "

All this is perfect, but google chrome warns me about this:

[Deprecation] Subresource requests using legacy protocols (like 'ftp:') are deprecated, and will be blocked in M59, around June 2017. Please deliver web-accessible resources over modern protocols like HTTPS. See https://www.chromestatus.com/feature/5709390967472128 for more details.

this is a future problem for my platform, since I keep the images on an FTP server so that I do not have space on the server

I would greatly appreciate a solution to my problem, thank you in advance. I do not think it is necessary to put code, because everything is fine, I am working on php and javascript for that part!

    
asked by user7649760 29.05.2017 в 23:35
source

3 answers

0

solution to my problem:

to the final download the image, but without saving it on my server, use the function file_get_contents of php, then code the string that returns this function to base64 and then in the src attribute of the IMG tag I put data: image / jpg; base64, as they do not weigh so much and the query is asynchronous, here the code is in case someone needs it:

$context = stream_context_create(array('ftp' => array('header'=>'Connection: close\r\n')));
$Imagen = file_get_contents($entry->Ruta, false, $context);
$imageData = base64_encode($Imagen);

echo '<img  id="ImgProd'.$i.'" src="data:image/jpg;base64,".$imageData." style="height:auto; max-width: 90%; border-radius: 5px;" class="form-control" name="sImagen"/>';

this works for me, because what a download ends, the image is displayed instantly while the other images are downloaded and so on.
thanks to those who commented and contributed ideas !!

    
answered by 02.06.2017 / 17:43
source
0

The simplest: it uses a proxy PHP, which converts HTTP requests into FTP requests.

It is not necessary to handle the FTP protocol completely. You can use the ftp_get( ) function, which frees all the work.

The idea is simple: you create a file ftp.php that is limited to get the file that you pass as a parameter, and send it by the PHP exit itself. In the official documentation of ftp_get () you have several examples about it.

This scheme presents 2 inconveniences:

  • Latency. FTP requests have a more complex protocol than HTTP, so the time to satisfy the request is greater.

  • Everything goes through PHP. No You will be able to take advantage of any cache mechanism on the server, which implies a greater use of resources, and a lower speed (which adds to the above).

  • In summary: this method is slow , but I think it is the only feasible solution in your case, if you do not want to copy those images to your own server.

        
    answered by 30.05.2017 в 00:05
    0

    I think your problem could be solved like this: sftp://user:password@domain/ruta/imagen.png , but for that to work, you might need to install a security certificate on your server and enable the sftp protocol

        
    answered by 30.05.2017 в 00:41