News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Create a Post with attachments

Started by tdguchi, December 17, 2014, 03:24:22 PM

Previous topic - Next topic

tdguchi

Im coding for a script in php for smf 2.0.9....

it get an image url, downloads it on attachment folder (name image.jpg).. then, i need to attach the image to a new post using createpost()....I know that there is a funciont called createattachment() but i dont know how to use it... my code goes as here:

$attachmentOptions = array(
'poster' => $user_info['id'],
'name' => "portada",
'tmp_name' => "image.jpg",
'size' => filesize("image.jpg"),
'approved' => 1,
'id'=> 2,
);

createAttachment($attachmentOptions);


// Create the post
require_once($sourcedir . '/Subs-Post.php');
$msgOptions = array(
'id' => empty($_REQUEST['msg']) ? 0 : (int) $_REQUEST['msg'],
'subject' => $subject,
'body' =>  $message,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(2),
);


in that example, the image is located on the same folder, within the script.... smf gives no error, but only the post is shown, the image is not attached....

In the script. everytime its launched, it gets a diferent image, downloads it, creates the new post, and attaches the image.... (that is the goal)

how can i do that?

thanks

Arantor

createAttachment is expecting to deal with files that were uploaded from the user, which means $_FILES is handled, and security tests are carried out on that.

You won't be able to do it directly with createAttachment without unsecuring the function in SMF.

tdguchi


Arantor

Not with the in-built functions, no.

You could do the inserts/file moves manually, or copy createAttachment as a base.

tdguchi

ok.... i have no idea how to do that.... im not a newbie programmin in php... but i dont have the knowledge...

Advertisement: