Upload to other domain
Upload to other domain
Field::inst('tb_usuario.imagem')
->setFormatter('Format::ifEmpty', null)
->upload(Upload::inst('http://MY_OTHER_SITE.COM/image/__ID__.__EXTN__')
->db('tb_imagem', '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(function ( $file ) {
return $file['size'] >= 2000000 ?
"Imagens devem ser menor que 2MB" :
null;
} )
How to upload a image to other site? I have 3 sites and I want store the images in a unique local.
This question has accepted answers - jump to:
Answers
You'd use a custom upload action. Instead of a simple
move_uploaded_file
(unless you've got a network mount of your other site I suppose) you'd need to use an API to upload the file to the other site - S3 for example, or FTP.Allan
I am trying:
But I receive the error: Cannot set path information in database if a custom method is used to save the file.
The error is correct - if you are using a custom function to manipulate the uploaded file (in this case sent it to an ftp server) we can't know what the web-path will be. You need to remove:
Allan
Thanks Allan, one more question: the function
ftp_connect()
is not recognized, why?How to call a PHP function inside the Field code?
If you have ftp support for PHP compiled in, then it should be a global function. If PHP is saying it isn’t a known function, then it suggests to me that ftp support hasn’t been included in however that PHP install was compiled.
Allan