genrimages
clone your own copy | download snapshot

Snapshots | iceberg

Inside this repository

import-document-visuel.php
text/x-php

Download raw (1.7 KB)

<?php
//Bootstrap start
define('DRUPAL_ROOT', '/var/www/html/genrimages/plateforme/site');
$_SERVER['REMOTE_ADDR'] = "localhost"; // Necessary if running from command line
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
include_once("includes.php");
$f_name="../annotation/data-sophie-17-02-2017/data/1485964326.ser";
$str_ser=file_get_contents($f_name);
$fiche=unserialize($str_ser);
/* var_dump($fiche); */
$img_path='images/'.$fiche->get_url();
$nodev = new stdClass(); // We create a new nodev object
$nodev->type = "document_visuel"; // Or any other content type you want
node_object_prepare($nodev); // Set some default values.
$nodev->title = "Image pour la fiche ".$fiche->get_title();
$nodev->field_description_non_voyants['und'][0]['value'] = $fiche->get_url_descriptor();
$file_path = drupal_realpath($img_path);
$file = (object) array(
		       'uid' => 1,
		       'uri' => $file_path,
		       'filemime' => file_get_mimetype($file_path),
		       'status' => 1,
		       'display'=>0
		       );
// You can specify a subdirectory, e.g. public://foo/
/* print_r($file); */
/* print_r($file); */
$file = file_copy($file, 'public://', FILE_EXISTS_REPLACE);
/* print_r($file); */
$nodev->field_visuel[LANGUAGE_NONE][0] = (array) $file;
$nodev->language = LANGUAGE_NONE; // Or any language code if Locale module is enabled. More on this below
$nodev = node_submit($nodev); // Prepare node for a submit
print $fiche->get_url()."\n";
print $nodev->field_description_non_voyants['und'][0]['value']."\n"; 
print_r($nodev);
/* print_r($nodev); */
node_save($nodev); // After this call we'll get a nid
/* system("firefox http://localhost/genrimages/plateforme/site/?q=genrimages/annotation_ensemble_edit/".$nodev->nid); */
?>