Its also possible to use MIGX or MIGXdb to get, what you want.
Currently I'm working on a project, where redactors upload images for news into an upload-directory by ftp with defined file-names.
I have a snippet, which is running in the MIGX-TVs input-options:
@EVAL return $modx->runSnippet('sn_News_getImages_for_migx');
the snippet is searching for files with the prefix of the pagetitle, of the currently edited resource.
It creates a file-directory with the same name as the pagetitle, imports the images to that directory and imports them into the MIGX-TV, where they can add additional informations to each image.
The snippet does currently look like that:
$docid = 0;
if (isset($_REQUEST['object_id'])) {
//in CMP
$docid = $_REQUEST['object_id'];
} elseif (is_object($modx->resource)) {
//in resource-manager
$docid = $modx->resource->get('id');
}
$id = $modx->getOption('id', $scriptProperties, $docid);
if (empty($id)) {
return '';
}
if ($doc = $modx->getObject('modResource', "$id")) { // Verbindung id mit Resource
$pagetitle = $doc->get('pagetitle'); // Auslesen des Resourcen Titles
}
$uploadpath = $modx->getOption('pfad', $scriptProperties, 'inhalt/mediaRedaktion/bilder_news_upload');
$uploadpath = $modx->getOption('base_path') . $uploadpath;
$imagepath = $modx->getOption('pfad', $scriptProperties, 'inhalt/mediaRedaktion/bilder_news');
$imagepath = $modx->getOption('base_path') . $imagepath . '/' . $pagetitle;
/* AUSLESEN DER BILDER IM UPLOAD VERZEICHNISS
------------------------------------------------------ */
$alledateien = scandir($uploadpath); // liest alle Dateien in dem Verzeichnis aus, das mit der Variable &pfad an das Snippet uebergeben wurde
$i = 0; // $i zum Numerieren der Bildnamen im Array $bilder mit 0 starten
$bilder = array(); // Array $bilder für die Bildnamen definieren
foreach ($alledateien as $bildname) { // Ausgabeschleife, der Dateiname wird jeweils in $bildname uebergeben
if (preg_match("/$pagetitle/", "$bildname")) { // wenn im Bildnamen der Pagetitle enthalten ist...
$bilder[$i] = $bildname; // ... wird der Bildname unter der aktuellen Nummer $i in das Array gepackt
$i++; // Dann wird $i eins hochgezaehlt
}
}
$anzahl = count($bilder);
if (!$anzahl) {
//keine Bilder gefunden
// evtl. vorhandenes Verzeichnis entfernen
if (file_exists($imagepath)) {
if (!@rmdir($imagepath)) {
}
}
return '';
}
/* BILDORDNER ERSTELLEN
------------------------------------------------------ */
if (!file_exists($imagepath)) {
if (!@mkdir($imagepath, 0755, true)) {
$modx->log(MODX_LOG_LEVEL_ERROR, sprintf('[sn_News_getImages_for_migx]: could not create directory %s).', $imagepath));
}
}
/* GEFUNDENE BILDER IN EIGENEN ORDNER JE NEWS VERSCHIEBEN
------------------------------------------------------ */
foreach ($bilder as $bild) {
$source = $uploadpath . '/' . $bild;
$target = $imagepath . '/' . $bild;
rename($source, $target);
unlink($source);
}
/* AUSLESEN DER BILDER IM NEWS-IMAGE VERZEICHNIS
------------------------------------------------------ */
$alledateien = scandir($imagepath); // liest alle Dateien in dem Verzeichnis aus, das mit der Variable &pfad an das Snippet uebergeben wurde
$i = 0; // $i zum Numerieren der Bildnamen im Array $bilder mit 0 starten
$bilder = array(); // Array $bilder für die Bildnamen definieren
foreach ($alledateien as $bildname) { // Ausgabeschleife, der Dateiname wird jeweils in $bildname uebergeben
if (preg_match("/$pagetitle/", "$bildname")) { // wenn im Bildnamen der Pagetitle enthalten ist...
$bild = array();
$bild['image'] = $bildname;
$bild['id'] = $bildname;
$bilder[$i] = $bild;
$i++; // Dann wird $i eins hochgezaehlt
}
}
$anzahl = count($bilder);
return $modx->toJson($bilder);