In simplest terms, I have a file select form which allows for multiple files to be selected for upload:
<form enctype="multipart/form-data" method="post" id="image_upload_form">
<input type="file" multiple="multiple" id="image_upload" name="files_to_upload[]" onchange="ini_image_upload();" />
</form>
Once files are selected, I run a quick Ajax call to check the database if certain files have already been uploaded, make sure there's no invalid files, etc. and create an array of files that already exist/I don't want to upload.
Now, I am trying to REMOVE these unwanted, scummy files from my upload array (before the actual upload IE. form gets submitted).
How do I achieve this majestically feat?
I have one suggestion for you. It is better to use below for your
requirement for upload. Have a look onto below URL.It is really so easy to integrate into your existing system and lots of features available.
http://www.uploadify.com/
what are you going to validate files by? are you trying to remove files with like some tricky extenstions like .php, .asp, .aspx ? if so then in the form element you should add a onSubmit attribute and call a function from there. then in the function check all the file names and process them and remove them from the array then replace the upload array and then return true. it would submit the form.. I actually don't know how u can retrieve the filenames form the upload array but Im pretty sure that this solution should work.
good luck!
Related
I need to get the full file path including file name information to handle later with PHP.
I am running into many difficulties.
We can use a html form with the html
<form method="post" enctype="multipart/form-data">
<input type="file" />
However, to pass this information we need to the server, we actually have to upload the file, I do not want to do this as its wasteful, The reason being is that this project is just for my local machine, The file already exists on my machine.
A manual way of achieving this is to provide a input text field, and inserting the file(s) full location path here via another file navigation window(copy/paste), But this quickly becomes boring and requires to much work when using the tool often.
Any other suggestions to achieve this?
This isn't possible. This has been discussed before and the explanations they give there are good, so I won't repeat:
How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?
paste following line under file tag,your problem will be solved
webkitdirectory directory multiple
<input type="file" id="ctrl" webkitdirectory directory multiple/>
I have build a form in which you can add images. Unfortunatelly, I am not able to call "move_uploaded_file" in PHP, as the server is running PHP safe mode and there is no way to modify this (I have checked). Therefore, I submit my form to my OWN server, which handles the file uploading.
On my own server, the file however; is not found. I think it has to do with the form calling the external url.
I know this because
echo $_FILES['uploadFile']['name'] ."<br>";
returns just an empty line.
The form itself is:
<form action="http://ejw.patrickh.nl/load.php" method="get" enctype="multipart/form-data" onsubmit ="return checkInput();"> </form>
and contains several input buttons.
Bottomline: the form on my own server submits the file perfectly, however when I make use of the form which is on another site, with the above action; no file is found.
Can this be fixed, and if so; how?
Thanks in advance!
You have to use method="post" to submit files.
Also the enctype attribute alone can be used only, if method="post".
I need help with my form. There's a mix of input, textarea and file upload that i want to enter into the database..
What do I use in the ? Do I use the normal form attribute :
<form action="" method="">
or
<form enctype="" action="" method="">
Please have it in mind that, I have to do this in a single page, and the picture upload must be done along with other text input.
Thanks for your time.
You must use enctype="multipart/form-data" for file uploading, this will also work fine for non-file upload forms.
You need to set enctype="multipart/form-data" and use method="post" for any form that includes a file input. This won't stop you from including other types of fields.
(The way those fields will be submitted to the server will change, but your form parsing library will deal with the differences automatically, you only need to worry about them if you are parsing the raw input yourself).
<form enctype="multipart/form-data" method="post" action="submit.php">
submit.php being, in this case, the external PHP script that will process your form ( if you decide to use PHP ). But you can name the .php script whatever you like ( e.g. cats.php ).
The uploaded file/image data will be stored inside $_FILES, and all the textfield, textarea, radio buttons, check boxes and other data will reside inside the $_POST superglobal.
When submit.php receives the submitted form you can do all kinds of processing on it such as validating that user has submitted the correct type of file/image, store the file path of the file/image in your local database( client/server or file system based ), and much more.
Make sure to validate user input client side and server side too.
<form enctype="multipart/form-data" action="yourpage.php" method="post">
You'll need the enctype attribute if you want the file upload to work. FYI, a form can contain every field type, including file uploads, and work just fine.
In Classic ASP I had to access my textfield as load.getFileData("textfield")
instead of the standard Request("textfield") when using the enctype="multipart/form-data"
I am currently working on php project where I need to upload files, but I have no way of knowing how many files the user will upload.
There will be one file upload by default on the form with a link to add another file upload. When the form is submitted how would I post all of the files to the php script if I don't know the number of files that are being uploaded.
Does it work in the same way as a checkbox array so you could have something like
<input type="file" name"myFile[]" />
<input type="file" name"myFile[]" />
Thanks for any help you can provide.
Yes, works fine.
try to do this, after post form with files:
<pre>
<?php print_r($_FILES['myFile']['tmp_name']); ?>
</pre>
You will get a array. Access each file info with their index:
$_FILES['myFile']['tmp_name'][0];
$_FILES['myFile']['tmp_name'][1];
Yes, it works exactly like a checkbox array.
<form enctype="multipart/form-data">
<input type="file" name="mp3" />
<input type="submit" />
</form>
I tried the above,and found var_dump($_FILES); is always empty.
It only works when you upload text files or images.
UPDATE
I added method="POST" and it works.Why is POST necessary here?
MP3 file uploads should work like any other file upload, there's no discrimination by file type or extension.
Check whether your file is not larger than allowed.
PHP manual on file uploads
PHP manual on file uploads: Common pitfalls
Update: #Adhip Gupta solved it. GET seems to be the default method for a FORM, not POST as I thought. Check here: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1
This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post". See the section on form submission for usage information.
Did you specify the form method to be POST explicitly and try?
First thing to check is how big the files are, and what the max upload size in PHP.ini is set to.
Nothing wrong with your PHP code. And neither PHP nor the webserver know the difference between a MP3 file and other types of content.
Have you checked its not size related?
Do you know that there isn't other things between the browser and the PHP which might be filtering?
Have you tried using a wiretap (e.g. wireshark) to confirm the data is leaving the browser / getting to the server?
C.
Maybe you have missed the MAX_FILE_SIZE which should be included.
<input type="hidden" name="MAX_FILE_SIZE" value="157286400" />
You should also add action="some.php" and method="POST" to <form>
OR using http://www.uploadify.com/ with ajax