Comments (16)
Hi,
Here's the docs on file uploading https://www.jaxon-php.org/docs/requests/upload.html.
from jaxon-core.
from jaxon-core.
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.
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.
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.
Hi,
Do you have any error message? What does the jaxon()->getUploadedFiles()
function return?
from jaxon-core.
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.
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.
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.
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.
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.
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.
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.
$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.
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.
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)
- Call to undefined function Jaxon\CodeIgniter\Filter\jaxon() HOT 2
- Jaxon-Upload Help
- CSP if SSL is in use...
- Examples links are returning an Error HOT 4
- Reinstate CallableObjects in version 4 possible? HOT 2
- PHP 8.2 warning: Deprecated: Creation of dynamic property Jaxon\Utils\Template\Context is deprecated HOT 2
- work with swoole framwork HOT 3
- Problems running most jaxon examples HOT 1
- Uncaught TypeError: Jaxon\Plugin\Request\CallableFunction\CallableFunction::configure(): Argument #2 ($sValue) must be of type string HOT 1
- Paramter as string '0' HOT 1
- Going from V2.x to V4.x HOT 6
- Stuck on 3.8.2; will not update to latest
- myJaxon extends Jaxon || myResponse extends Response HOT 10
- Register CALLABLE_CLASS problem HOT 6
- Jaxon with single class file per web page HOT 7
- Jaxon and the factory pattern HOT 21
- Directory Registration HOT 4
- Small Replacement for Most Used Response methods
- register existing method in object HOT 3
- options.filter is not a function when using getFormValues with a multiple-select HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxon-core.