Smarty Uploading a File with normal Input Files - php

In my index.php file , I got a code is trace the $_FILE, but seems like when uploaded a pic/jpeg/images file, the return result is 'array(0) { }'. Did I need use smarty's method to assign a input file's method?
var_dump($_FILES);
my photoupload.tpl
<form action="index.php?view=photoupload" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<input class="btn_name" type="submit" name="submit" value="Submit">
</form>

No, you dont have to, heres a part of my current project where i work with smarty:
<form action="upload_contract.php" enctype="multipart/form-data" method="post">
...
<div class="row">
<div class="large-5 columns">
<label for="upload">Dateiupload:</label><span><input type="file" id="upload" name="upload"></span>
</div>
</div>
This one works fine without additional methods.

Related

$_FILES uploads only 1 file

<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_1" class="fileChoose" accept="image/*"></br></br></br>
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_2" class="fileChoose" accept="image/*"></br></br></br>
It only fills the first image and the second one it gives an errors: "4", how to fix it,
I want multiple input fields not 1 multiple :D
if you put the form with
<form method="POST" enctype="multipart/form-data" >
two items are returned to you
try like this
<?php
var_dump($_FILES['images_1']);
var_dump($_FILES['images_2']);
?>
<form method="POST" enctype="multipart/form-data" >
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_1" class="fileChoose" accept="image/*"></br></br></br>
<label class="labelFile">Bestand kiezen...</label>
<input type="file" name="images_2" class="fileChoose" accept="image/*"></br></br></br>
<button value="ppp" type="submit">send </button>
</form>

Form not sending file when submitted with Jquery

I have this form:
<label for="pdffile">Upload</label>
<form class="form-horizontal" role="form" method="POST" name="upload" id="upload" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="file" id="pdffile" style="display:none" form="upload"
</form>
It is supposed to be submitted with this jquery:
$('#pdffile').change(function() {
$('#upload').attr("action", "/upload").submit();
});
However when I check in PHP, nothing is uploaded:
dd($request)
Always gives me back null instead of the requested item.
Any help?
Your input does not have name
<input type="file" id="pdffile" style="display:none" form="upload"
change to
<input type="file" id="pdffile" style="display:none" name="upload"/>
and in your action you can use $_FILES to get upload file

Upload Multiple file

Source Code :
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
I want to select all file from directory using file upload control and send one by one file to uploadrit.php.
You should add multiple attribute to your file tag:
<form role="form" action="uploadrit.php" method="post" enctype="multipart/form-data">
<label class="input" >Choose File Of CSV Format</label>
<input class="input" type="file" name="file" multiple id="file" class="form-control" required="required">
<button class="input" type="submit" name="AddFile" class="btn btn-primary">Submit</button>
</form>
If you need to handle the files via Javascript, you can use File API. Example documentation: http://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
Instead sending the files one by one, use the multiple flag and send the files as an array. Here is an example:
<form action="file-upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple>
<input type="submit" value="Upload">
</form>
Pay attention to input where I've used the multiple flag as well as have declared the name of the input as an array. In your PHP file, loop through $_FILES['files'] to get all selected files.

php function call direct as html form action

I have found that following HTML form code
<form action="<?php foo(bar)?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="submit">
</form>
works fine when foo(bar) is a function available in the current scope.
I am very new to php and html and couldn't find any documentation of this functionality online. Are there any downsides of using <?php foo(bar)?> instead of calling a script file foo.php?
The PHP function will not be called as a HTML form action.
Actually the PHP function will be executed before the server send the form to your browser, so the form's action will be the value printed by the foo function if it did.
Just open the web page's sources received from your server, you shouldn't see anymore PHP code.
This wouldn't work. The server is executing PHP before sending HTML to the browser.
But here's an idea:
<?php
function foo($bar)
{
echo $bar;
}
if (isset($_POST['func'])){
foo($_POST['file']);
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="hidden" name="func" id="file" value="foo">
<input type="submit" name="submit" value="submit">
</form>
But IMO a better way would be to use CURL or other url-catching-and-pointing-to-controller systems, like e.g. with a Framework

JQuery AJAX equivalent of form's submit file

I have a form, like this
<form id="picuploadform" enctype="multipart/form-data" method="post" action="">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
Which when I click the submit button I have PHP on this page to process it just fine. $_FILES for receiving file and $_POST for reading picssn that came with the hidden input. But due to problem with Jquery mobile I can't use submit or .submit() now. So I want to use
$.post('myphpfile.php', {picssn:$('#picssn').value(), file: $('#fileToUpload').xxxxxxxxxxxxxxxxx });
instead. But I have no idea how to grab the file out of that form and send it this way. Is there some method that can replace xxxxxxxxxxxxxx ? Thanks!
On your form element, you need to disable the ajax submit, and then fix your other code.
Try this:
<form id="picuploadform" enctype="multipart/form-data" method="post" action="#" data-ajax="false">
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" name="fileToUpload" id="fileToUpload" />
<input type="hidden" id = "picssn" name="picssn" value="qweweqwq">
</div>
<div class="row" style="width:150px;">
<input type="submit" value="Upload" />
</div>
</form>
You cant upload directly via ajax. Check this perhaps:
http://blueimp.github.com/jQuery-File-Upload/ or uploadify.com

Categories