i searched again and again but could not find the right answer. here is the situation. i got more than one forms in the same php file and below shows the code.
when i echo as below
echo count($_FILES["fileUploadPath"] );
it shows 0 as the count and
Notice: Undefined index:
addProjectFileUploadPath in C:\wamp...
updated: probelm solved..... error came due to 3rd party jquery plugin called "fileinput"
add enctype="multipart/form-data" to the form
Try looking at the entire array with this:
echo "<pre>".print_r($_FILES,true)."</pre>";
Then use this manual page to let you know what the error numbers mean. That will probably give you a good idea of what is going on.
PHP File Upload Error Codes
Okay, there are a couple of things you need to be aware of.
1) You can have as many forms on a page as you want, but you can only submit one of them. You need to make sure the form you expect is being submitted. I'm assuming you're using the submit button names for doing this. However this can result in problems if someone submits the form by hitting enter in a text entry region, the button won't be submitted. A hidden field would be better as it would always be submitted.
2) There doesn't seem to be a MAX_FELE_SIZE form input anywhere in your file upload form. File uploading will not work without it. You need to put something like <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> before the file inputs on your form.
I had the same problem before and I noticed that It happens when I don't close the tags, so try closing all input tags like this:
<form action='upload.php' method="post" enctype="multipart/form-data">
<!-- at the end of the input add / -->
<input type='file' name='file' />
<input type='submit' name='upload' />
</form>
Related
So I have a form that requires a user to submit their website to a form. Here is the html line:
<input type='url' name='link'>
And I'm using <input type="submit" value="submit" formmethod="post"> to submit the form to a php
And I'm trying to retrieve the values in my php file with:
$link = $_POST['link'];
Why isn't this working? At first I thought it was because I had htmlspecialchars() but it's not coming through without it either. I can't find anything in any google search that even mentions anything related to this kind of problem (with a type="url" form)
What do I need to do to process form data with type of "url" in PHP with a $_POST?
Get your form method to be set to post e.g
<form method=post>,
if you submit the form and in the url in your browser u can see some more inf then be sure 2 check your form method
I think this is wrong,
method="post"
Its only method, not formmethod
Also make sure, you dont have one more for element name with link.
After alot of digging around some very informative posts and info to try and find out how to solve this issue I thought I would ask around to see if anyone has any pointers.
I have an html form with various inputs (checkboxes, text boxes etc...). Each input section has its own submit or 'Upload' button. On Upload a php script is called and various bits of processing is done before data is sent over a pipe to a Python script for further stuff.
I am currently echoing back input variables to the form on submission so that the html page does not refresh (or should I say the inputted data is not lost to the users view) on an Upload event, however, I now have to do the same for a bunch of checkboxes and text boxes the values of which are stored in an array. The code I have written so far is as follows (I am new to both php and html so please excuse the inefficiency that I'm sure is obvious)
html/php
<margin>CH1</margin><input type="checkbox"name="ANout[]"value="AN1_OUT"
<?php if(in_array('AN1_OUT',$_POST['ANout']))echo'checked';?>>
Voltage<input type="text"size="5"name="ANout[]"
value="<?php $ANout[$i]=$_POST['ANout'];
if(!empty($ANout[$i]))echo"$ANout[$i]";?>">
<br>
The code above works fine for the checkboxes which happily remain after an Upload button is pressed but not for the array. When the Upload event occurs I simply get 'Array' written in the text box. I have tried existing code I have written to echo back other text input in the form (see below) and which works but these are for sole entries, not arrays. I have tried various configurations of syntax but I always seem to get the same result.
Working Code:
<margin>Duty Cyle</margin><input type="text"name="PWM1DC"size="3"
value="<?php $PWM1DC = $_POST['PWM1DC'];
if(!empty($PWM1DC))echo "PWM1DC";?>">
<br>
I'm sure it is something straightforward but I have been fiddling and staring at it for ages and can't seem to find the problem.
You are getting "Array", because you are trying to print out variable of type Array.
You probably want to give your fields separate names or indexes and do something like this:
<form method="post">
<input type="checkbox" name="ANout[1]" value="AN1_OUT"
<?php if(isset($_POST['ANout']) && in_array('AN1_OUT',$_POST['ANout']))echo'checked';?>>
Voltage<input type="text"size="5"name="ANout[2]"
value="<?php if(isset($_POST['ANout']) && !empty($_POST['ANout'][2])) echo $_POST['ANout'][2]; ?>">
<input type="submit" value="ok">
</form>
(Just added form tags, submit button and isset checks to show working example.)
I have the following form:
<form id="vintro-upload-form" action="{url}?nexturl={nextUrl}" method="post" enctype="multipart/form-data" >
<input name="file" type="file"/>
<input name="token" type="hidden" value=""/>
<input value="Upload Video File" type="button" name="submit" onClick="checkFile()" class="button" />
</form>
and the following javascript:
<script>
function checkFile(){
var fileVal = document.forms["vintro-upload-form"].elements['file'].value;
//RegEx for valid file name and extensions.
if(fileVal != ""){vintro-upload-form.submit();}
else {alert('Please select the Video file.');}
}
</script>
What works? The fileVal assignment is good. Submit isn't working, when I checked the debugger, it is saying: "vintro is undefined."
What have I tried?
The following examples and code:
http://www.w3schools.com/jsref/met_form_submit.asp
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml
document.vintro-upload-form.submit();
document.forms["vintro-upload-form"].submit();
document.getElementById("vintro-upload-form").submit();
changed the dashes/hyphens to underscores
All to no success. There is some jQuery (in another .js file) going on with this form as well, and it functions properly with the hyphenated name.
Why is the submit call not working?
EDIT:
I have tried using document.getElementById('vintro-upload-form').submit(); as suggested in the answers to this question, however, this is still failing. My (Firefox) debugger is saying that it is not a function. Chrome's debugger explained a little bit more: "Uncaught TypeError: Property 'submit' of object # is not a function" (I'm going to Google this in the meantime.)
Since I have less than 100 reputation:
Ok, so it turns out, I was asking the wrong question.
Here's the answer I found:
Submitting Form Via Javascript, form defined in external PHP file
Check the accepted answer as well.
This JavaScript:
document.forms["vintro-upload-form"].elements['file'].value
is looking for the NAME attribute of the form tag:
document.forms[{form_name}].elements[{field_name}].value
You just have an ID. Copy the value of the ID to a NAME and you're done.
However, document.getElementById() is the preferred, modern way of doing this with plain JavaScript.
HOWEVER: You can't have a submit / button named "submit".
When you do and you call the JavaScript submit() function, you get a conflict.
You simply need:document.getElementById('nameofform').submit() is easier to find elements by its id than for the name.
Other way is to get elements by name, you can do it with document.getElementsByName('nameofform')...But that returns an array so you need to iterate that array to find which of those forms is needed to be uploaded. So, I think you should use the id.
The name of your form contains characters that cannot be used in a JavaScript identifier (dashes). Use document.getElementById('vintro-upload-form').submit(); instead.
I am doing some simple work with uploading a file. I am ignoring error checking and exceptions at this point just to get my uploads working. I have this HTML form:
<form action='addResult.php' method='post' enctype='multipart/form-data' target='results_iFrame' onsubmit='startUpload();'>
Entry: <input type='text' id='entry' />
Stop: <input type='text' id='stop' />
Final: <input type='text' id='final' />
Chart: <input type='file' id='chart' />
<input type='submit' value='Add' /></form>
As you can see, it calls 'addResult.php' within the iFrame 'results_iFrame'. The Javascript is just for animation purposes and to tell me when things are finished.
addResult.php has this code in it (along with processing the other inputs):
$upload_dir = "../img/";
$chart_loc = $upload_dir.basename($_FILES['chart']['name']);
move_uploaded_file($_FILES['chart']['tmp_name'], $chart_loc);
print_r($_FILES);
It uses the 'chart' input from the form and tries to upload it. I have the print_r() function to display some information on $_FILES, but the array is empty, thus making this fail. What could I be doing wrong?
When dealing with forms, the name= is used to reference items serverside, not the id=.
Just change all those id attributes to namess, and you're good to go (hopefully).
You have to give your input elements name attributes or they don't get passed to your script. The id is used for DOM/browser/client-side use.
There might be another problem after you resolve this, but this is a good first step.
Try adding the name attribute to your input values like so:
<input type='file' id='chart' name="myfile"/>
Your inputs have no "name" attribute, only IDs.
You need to give your form fields name attributes
My PHP book gives a template HTML form for uploading a file:
<form action="upload.php" method="post" enctype="multipart/form-data"/>
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<label for="userfile">Upload a file:</label>
<input type="file" name="userfile" id="userfile"/>
<input type="submit" value="Send File"/>
</div>
</form>
The book displays it as "Upload a file:" [textbox] [Browse...] [Send File]
I copied it verbatim, and the result I'm getting is "Upload a file:" [Choose File] "no file chosen" [Send File]
I'm wondering why the discrepancy exists. Is there a way around it? I'm using XHTML Transitional. No doctype is given in the book. But I doubt that's the issue.
The script I'm writing aims to take the file the user chooses, process it, and write the result into another file that doesn't exist yet. I'm asking this question because it would be useful to let the user more easily copy the initial file path/name, paste it into the other field, and just change a part of it.
(Also: why the difference between "Browse..." and "Choose File"? I tried manually setting the value of the "userfile" field to "Browse..." but nothing happened. This is less important but I'm curious nonetheless.)
It is probably showing a different browser and/or version.
It sounds like you are looking at it under Safari and the book has screenshots of IE, for example.
There are a few ways to get complete control of file uploading and the <input type="file" /> element. You can use Flash, or you can set the input to opacity: 0 and then position what you want beneath it.
Some time ago the browser engines took almost complete control over the input type="file" - fields, since it nowadays is regarded as a security issue. For example the days before that you could easily prefill the file input filed with some path and filename (e.g. something like /etc/passwd) and hide the field, so sending the form you would not remark that you're also sending the file...
That's why for example you could not preset the filename of such a field and that's also why browsers now all do their own thing with these special input fields.
As Alex said above, you could get around this, but it will be some hassle, because it would mean to "fake" the file input field.