node save with images

Posted: Wed, Jun 06, 2012 - 10:46am

hai........... i want to add a node using node_save . i have a doubt about images adding into node . i want to images add to node without download to the local server . image url taken from remote .iam doing like this way...

<!--?php global $user; $node = new stdClass(); $node--->

type = 'hotel_image'; $node->language = 'und'; $node->title='surya'; $node->field_image_hotel_id[$node->language][0]['value'] =123456; $node->uid=$user->uid; $node->status=1; $url = ''; $url= file_stream_wrapper_uri_normalize($url); $filesize=remotefilesize($url) ; function remotefilesize($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 200 $filesize = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); //filesize curl_close($ch); if( 200 != $status ) throw new Exception('File not found!'); return $filesize; } $file = new stdClass(); $file->fid = NULL; $file->uri = $url; $file->filename = basename($file->uri); $file->filemime = file_get_mimetype($file->uri); $file->uid = $GLOBALS['user']->uid; $file->status = FILE_STATUS_PERMANENT; file_save($file); but i got an error Warning: filesize() [function.filesize]: stat failed for in file_save() (line 573 of /var/www/divya/travel-dev/includes/ .. pls help me..

Hi preetha, do you want the

  • Tue, Jan 01, 2013 - 09:53pm

Hi preetha, do you want the images to be linked from remote-server? If yes, I do not think you can link remote images that way to file fields in D7 (unless there's a stream wrapper for these I am not aware of).


Rahul Singla