Skip to main content
deleted 95 characters in body
Source Link

Updated:
Try with this code:


$image_original_path = '.. here my original path..';
$image_object = file_get_contents($image_original_path);
//$file = file_save_data($image_object,  $base_url.'/'.$filename, FILE_EXISTS_RENAME);
$file = file_save_data($image_object, file_default_scheme().'://images/'.basename($image_original_path),FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

Updated:
Try with this code:


$image_original_path = '.. here my original path..';
$image_object = file_get_contents($image_original_path);
//$file = file_save_data($image_object,  $base_url.'/'.$filename, FILE_EXISTS_RENAME);
$file = file_save_data($image_object, file_default_scheme().'://images/'.basename($image_original_path),FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

Updated:
Try with this code:


$image_original_path = '.. here my original path..';
$image_object = file_get_contents($image_original_path);
$file = file_save_data($image_object, file_default_scheme().'://'.basename($image_original_path),FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

added 24 characters in body
Source Link

TryUpdated:
Try with this code:


$image_original_path = '.. here my original path..';
$my_destination$image_object = 'sites/default/filesfile_get_contents($image_original_path);
/images/';
$my_new_name$file = 'my_image.jpg';
$filenamefile_save_data($image_object, = $my_destination$base_url.$my_new_name;
$image_object ='/'.$filename, file_get_contents($image_original_pathFILE_EXISTS_RENAME);
$file = file_save_data($image_object,  $base_urlfile_default_scheme().'://images/'.$filenamebasename($image_original_path), FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

Try with this code:


$image_original_path = '.. here my original path..';
$my_destination = 'sites/default/files/images/';
$my_new_name = 'my_image.jpg';
$filename = $my_destination.$my_new_name;
$image_object = file_get_contents($image_original_path);
$file = file_save_data($image_object,  $base_url.'/'.$filename, FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

Updated:
Try with this code:


$image_original_path = '.. here my original path..';
$image_object = file_get_contents($image_original_path);
//$file = file_save_data($image_object,  $base_url.'/'.$filename, FILE_EXISTS_RENAME);
$file = file_save_data($image_object, file_default_scheme().'://images/'.basename($image_original_path),FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}

Source Link

Try with this code:


$image_original_path = '.. here my original path..';
$my_destination = 'sites/default/files/images/';
$my_new_name = 'my_image.jpg';
$filename = $my_destination.$my_new_name;
$image_object = file_get_contents($image_original_path);
$file = file_save_data($image_object,  $base_url.'/'.$filename, FILE_EXISTS_RENAME);
// Add this code also
if (is_object($file)) { // if you get back a Drupal $file object, everything went as expected so make the status permenant
  $file->status = 1;
  $file = file_save($file);
}