pqina/filepond-boilerplate-php

Return array of final created file paths on after submit.

hasnatbabur opened this issue · 2 comments

Thanks for this awesome php work. There is a way to return an array of final created images paths so that we can save in database for later use? Thanks

Anyway I got a solution by editing this method in RequestHandler.class.php

here WTP_WATCH_PHOTOS_DIR = "/c/wamp/www/example.com/photos"
here WTP_WATCH_PHOTOS_URI = "http://example.com/photos"

`private static function moveFileById($fileId, $path, $fileName = null) {

    $newName = true;

    // select all files in directory except .htaccess
    foreach(glob(self::getSecureTempPath() . $fileId . DIRECTORY_SEPARATOR . '*.*') as $file) {

        $source = $file;
        $target = self::getSecurePath($path);

        self::createDirectory($target);

        // let's hash
        $__hash = md5(time() . "^%&&*^*&^");

        $newName = $target . "ph_{$__hash}_" . (isset($fileName) ? basename($fileName) : basename($file));
        rename($source, $newName);
    }

    // remove directory
    self::deleteTempDirectory($fileId);

    // done!
    // we can convert path dir to uri
    $file_uri = WTP_WATCH_PHOTOS_URI . '/' . basename($newName);

    return $file_uri;
}`

Then $files = FilePond\RequestHandler::save($items, WTP_WATCH_PHOTOS_DIR);

Where I get array all uploaded files uri.

Thanks

@hasnatbabur Was on a short trip so couldn't help out earlier, anyway, thanks for posting the solution!