Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename uploaded file #10

Open
norman784 opened this issue Dec 30, 2014 · 1 comment
Open

Rename uploaded file #10

norman784 opened this issue Dec 30, 2014 · 1 comment

Comments

@norman784
Copy link

Seems that the lib keep the original file name and there is no way that the server can tell ng-flow the new file name, my server output this on complete:

{
  "success":true,
  "flowTotalSize":58110,
  "flowIdentifier":"10152987551505362-2e68232139983ba857669baf3c2d45c7_development.jpg-58110",
  "flowFilename":"4498b3d20302c1c3b75ce37c1e5fefac",
  "flowRelativePath":"http:\/\/localhost\/images\/users\/4498b3d20302c1c3b75ce37c1e5fefac"
}

my upload script:

<?php
    $path = __DIR__ . '/../public/images/users/';
    $tmp = __DIR__ . '/../tmp/';

    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
      $chunkDir = $tmp . DIRECTORY_SEPARATOR . $_GET['flowIdentifier'];
      $chunkFile = $chunkDir.'/chunk.part'.$_GET['flowChunkNumber'];
      if (file_exists($chunkFile)) {
        header("HTTP/1.0 200 Ok");
      } else {
        header("HTTP/1.0 404 Not Found");
      }
    }

    // $file = $path . (isset($_FILES['file']) ? $_FILES['file']['name'] : $_GET['flowFilename']); // this is using original name, but in this case the file sooner or later will be overrite by other user that upload a file with the same name
    $file = $path . md5(time()); // The way I want, it need to add the extension but it was a test only

    if (isset($_FILES)) {
      copy($_FILES['file']['tmp_name'], $file);

      echo json_encode([
          'success' => true,
          //optional
          'flowTotalSize' => $_FILES['file']['size'],
          'flowIdentifier' => $_FILES['file']['name'] . '-' . $_FILES['file']['size'],
          'flowFilename' => basename($file),
          'flowRelativePath' => 'http://localhost/images/users/' . basename($file)
        ]);
    } else {
      if (\Flow\Basic::save($file, $tmp)) {
        echo json_encode([
          'success' => true,
          //optional
          'flowTotalSize' => $_GET['flowTotalSize'],
          'flowIdentifier' => basename($file),
          'flowFilename' => basename($file),
          'flowRelativePath' => 'http://localhost/images/users/' . basename($file)
        ]);
      }
    }
@AidasK
Copy link
Member

AidasK commented Feb 1, 2015

You just need to capture your output with ng-flow. It can be done on fileSuccess event which exposes your server side response message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants