Giter Site home page Giter Site logo

Upload Files about jaxon-core HOT 16 CLOSED

jaxon-php avatar jaxon-php commented on August 19, 2024
Upload Files

from jaxon-core.

Comments (16)

feuzeu avatar feuzeu commented on August 19, 2024

Hi,
Here's the docs on file uploading https://www.jaxon-php.org/docs/requests/upload.html.

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

The example code in the docs just works.
Make sure you have defined the required upload.default.dir option in your config, and the indicated directory is writable.
Also remember that Jaxon will only upload the files to a directory on your server. It is your responsibility to copy them elsewhere or rename them.

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

I've added a comment in the example class.

class Upload
{
    public function saveFile()
    {
        // Get uploaded files
        $aUploadedFiles = jaxon()->getUploadedFiles();

        // Do what ever you need with the files here

        return $this->response;
    }
}

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

Multiple files not Working

`require_once DIR . '/vendor/autoload.php';

    use Jaxon\Jaxon;
    use Jaxon\Response\Response;

    $jaxon = jaxon();

    $jaxon->setOption('core.debug.on', 1);

    $jaxon->setOption('upload.default.dir','upload');

    class Upload
    {
        public function saveFile()
        {
            $response = new Response;
            // Get uploaded files
            $aUploadedFiles = jaxon()->getUploadedFiles();



            return $response;
        }
    }


    $jaxon->register(Jaxon::CALLABLE_OBJECT, new Upload(), [
        'saveFile' => array('upload' => "'upload_example'")
    ]);

    $jaxon->registerClasses([
        Upload::class => [
            'saveFile' => array('upload' => "'upload_example'")
        ]
    ]);



    $jaxon->processRequest();`
    <html lang="pt-br" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
        <?php
        // Insert the Jaxon CSS code into the page
        echo $jaxon->getCss();
        ?>
      </head>
      <?   ?>
      <body>
        <form id="testeUpload" enctype="multipart/form-data">
        <input type="file" id="upload_example" name="example_files[]" multiple="multiple" />
        <input type="file" id="upload_example" name="example_files[]" multiple="multiple" />

        <button onclick="JaxonUpload.saveFile(jaxon.getFormValues('testeUpload'));return false;">Clique para enviar</button>

    </form>
      </body>

      <?php
      // Insert the Jaxon javascript code into the page
      echo $jaxon->getJs();
      echo $jaxon->getScript(true, true);
      ?>
    </html>

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

Hi,
Do you have any error message? What does the jaxon()->getUploadedFiles() function return?

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

I was able to upload, but when I create multiple fields I can not send all, it only goes 1 file. What to do in this situation?

<input type="file" id="upload_example" name="example_files[]" multiple="multiple" />
<input type="file" id="upload_example" name="example_files[]" multiple="multiple" />
<input type="file" id="upload_example" name="example_files[]" multiple="multiple" />

Another thing, I'm a little experienced in programming would like to know how to get the filename return in function jaxon()->getUploadedFiles() ?

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

You don't need multiple fields. A single input field with the multiple option set allows you to upload multiple files.
Moreover, HTML does not allow you to define multiple tags with the same id.

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

A call to jaxon()->getUploadedFiles() returns an array of Jaxon\Request\Support\UploadedFile objects.

https://www.jaxon-php.org/api/Jaxon/Request/Support/UploadedFile.html

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

I do not understand much with does to pull through the namespace can you cite an example in the code here so I understand better?

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

You don't need to call

    $jaxon->register(Jaxon::CALLABLE_OBJECT, new Upload(), [
        'saveFile' => array('upload' => "'upload_example'")
    ]);

and

    $jaxon->registerClasses([
        Upload::class => [
            'saveFile' => array('upload' => "'upload_example'")
        ]
    ]);

at the same time.

Only the frst is necessary in your case.

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

I'd like to understand how I can upload and when I get the names of the files being uploaded, I do not understand how to do this in code

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

Set a full path here

$jaxon->setOption('upload.default.dir','/full/path/to/upload/dir');

When you call jaxon()->getUploadedFiles(), the files have already been uploaded. You just need to pick them in the above directory.

from jaxon-core.

renatoandradeweb avatar renatoandradeweb commented on August 19, 2024

$jaxon->setOption can only be set generally, correct? I can not customize this folder within each function I will create if I have different folders to upload. Do you understand my precision? I need to upload on the system where I register some product and then the image, so I had to manipulate the file after sending it. I just wish they were in different folders because of the customizations I would like to make.

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

As it is stated in the docs (https://www.jaxon-php.org/docs/requests/upload.html), you can customize the upload dir by using the HTML field id in the option name, upload.upload_example.dir in your case.

Even with this feature, you must consider the upload dir as a temporary location. You are strongly adviced not to keep your files there.

What you do with the files once they are uploaded is out of the scope of the Jaxon library. Feel free to move them somewhere you can safely do whatever you need with.

from jaxon-core.

feuzeu avatar feuzeu commented on August 19, 2024

Just one more info, you can add the upload feature to any class or any method you want. Simply register it as in the example.
Having different classes can help applying different processing to the files.

from jaxon-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.