Upload image and get URL
1 naročnik
1 naročnik
Gre se za Wordpress.
Do koraka, kjer uploadam sliko v media library gre ok, uporabljam to kodo:
vfunctions.php
function insertattachment($filehandler,$post_id,$setthumb='false') {
// check to make sure its a successful upload
if ($FILES[$file_handler]['error'] !== UPLOADERROK) _return_false();
requireonce(ABSPATH . "wp-admin" . '/includes/image.php');
requireonce(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attachid = mediahandleupload( $filehandler, $post_id );
if ($setthumb) updatepostmeta($postid,'thumbnailid',$attachid);
return $attach_id;
}
V samem fajlu, kjer je forma za upload pa tole:
if ($_FILES) {
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
}
};
Problem, ki me muči, je, da ne znam skodirati, da bi lahko dobil URL uploadane slike, ki bi ga potem v naslednji vrstici dodal kot custom field.
addpostmeta($post_information..........
(edit: tole je samo izsek tiste kode, imam vse potrebno in ostale podatke iz forme mi normalno naredi v post, samo slike ne).
Delam čisto narobe? Se da nekako dobiti url ali pa vsaj ID uploadane slike? Hvala.