Monday, December 16, 2013

Upload Image in Drupalize Way

if($_FILES["field_your_profile_photo"]["name"]) {
$filename=uniqid().$_FILES["field_your_profile_photo"]["name"];
$_FILES["field_your_profile_photo"]["type"];
$_FILES["field_your_profile_photo"]["size"];
$_FILES["field_your_profile_photo"]["tmp_name"];
 move_uploaded_file($_FILES["field_your_profile_photo"]["tmp_name"],$_SERVER['DOCUMENT_ROOT']."/goodstreet/sites/default/files/product/" .$filename);
//print $profile->field_business_name['und'][0]['value'];
$image_path = 'public://product/'. $filename;
$image_info = image_get_info($image_path);
   //print_r($image_info); exit();
// create file object
$file = new StdClass();
$file->uid = $uid;
$file->uri = $image_path;
$file->filemime = $image_info['mime_type'];
$file->status = 0; // Yes! Set status to 0 in order to save temporary file.
$file->filesize = $image_info['file_size'];
print $file->filename=$filename;
file_save($file);
$profile->field_your_profile_photo = array(
'und' => array(
0 => array(
'fid' => $file->fid,
'filename' => $file->filename,
'filemime' => $file->filemime,
'uid' => $uid,
'uri' => $file->uri,
'status' => 1
)
)
);
}

No comments:

Post a Comment