I am not sure what is the benefit of using
system_retrieve_file mentioned on Save image from URL to a field from a custom module, so I just use the following simple code to save image programmatically:
$ file = file_save_data(file_get_contents($ url), file_default_scheme().'://field/image/'.basename($ url)); $ file->status = 1; $ node->field_image['und'] = (array)$ file; node_save($ node);
Works fine, so now I am trying to figure out how to save the enabled alt value which is stored in $ alt variable.
When I output what the $ file array contains with
dsm(print_r($ file,true)); it shows only:
stdClass Object ( [fid] => 9 [uri] => public://field/image/150304192032_monalisa_624x351_afp_0.jpg [filename] => 150304192032_monalisa_624x351_afp.jpg [filemime] => image/jpeg [uid] => 1 [status] => 1 [timestamp] => 1425596902 [filesize] => 28642 )
Unfortunately, it doesn’t contain neither title or alt. Could anyone help me to get this sorted out? Thanks!