I have created a form through my module in which the user(anonymous) can enter an image URL and some title for the image. The link needs to be, like with remote stream wrapper, shown as an actual image. So this means, the image should be used from an external sources and not be download on my local server.
$node = new stdClass(); // Create a new node object $node->type = "article"; // Or page, or whatever content type you like node_object_prepare($node); $node->title = filter_xss($_GET['title']); $node->language = en; // Or e.g. 'en' if locale is enabled $file_path = $_GET['link']; $file = (object) array( 'uid' => 1, 'uri' => $file_path, 'filemime' => file_get_mimetype($file_path), 'status' => 1, ); $node->field_image[$node->language] = (array)$file; $node->uid = 1; // UID of the author of the node; or use $node->name node_save($node);
I have this code and it doesn't save the image URL. I'm sending the 'link' and 'title' properties through AJAX.