0

I have following html

<form action="upload.php" method="get" enctype="multipart/form-data">
Enter 10 digit mobile number &nbsp;<input id="imgphno" type="text" maxlength="10" />
<br/><br/>
<input id="file" type="file" name="file" />
<br/><br/>
<input type="submit" name="submit" value="Send" id="sndimg"/>
</form>

when i run it browser address bar shows

http://116.75.128.138/balasaheb/upload.php?file=thumb.jpg&submit=Send

how do i access the textbox contents in upload.php?

2 Answers 2

2

You are using GET method to send form's data to upload page.

You can reach that variables using _GET["submit"] _GET["file"]

And add name property to <input id="imgphno" type="text" maxlength="10" />

But you need to send data using POST method to reach contents of thumb.jpg.

Sign up to request clarification or add additional context in comments.

5 Comments

actually i am using POST but to include the url i did that. Files are being uploaded successfully but i am not able to access the context of text box. That is my question.
You have to add name property to imgphno input element. It should be like <input id="imgphno" type="text" maxlength="10" name="telno" /> after that you can see that input area on the url and you can reach it.
_GET you're missing something crucial. Plus, _GET["file"] won't work. POST must be used when uploading files, therefore you need to edit your answer accordingly for future visitors to the Q&A.
thx solved the issue. Actully i didnt knew we do need yo use name also ! :D thx nyways
You need to use name property to reach that control. The name property is the same as x:Name from WPF. The ID part is just for the javascript.
1

_POST empty while using file and text in form

When uploading files, POST must be used and not GET. Uploads won't work with the GET method.

  • Reason being is that you are using a GET method. Change your method to method="post"

Also make sure your PHP contains $_POST and not $_GET which you haven't shown us.

If you want to get the value of the text box use, and name your form element:

<input id="imgphno" type="text" maxlength="10" name="textbox" />
                                               ^^^^^^^^^^^^^^

then use it as:

$text = $_POST['textbox'];

you can't rely solely on id but name to pass a form element.

then do as you wish from there, but use POST again... not GET since you're uploading also.


As per the manual http://php.net/manual/en/function.move-uploaded-file.php

This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

Another answer given on Stack to support this:

move_uploaded_file() is only for files that were uploaded via POST.

5 Comments

Explanation for the DV? I'm right. Uploading does NOT work with GET, fact.
you didnt got my question properly. I wanted to get values of the text box that is being used.
@Abhi I added some additional information about PHP's upload mechanism to support my answer regarding using the POST method.
yup buddy thanks a lot. i already knew that just a little confusion between name and id tags! thanks anyways. accepting your reply as answer.
@Abhi You've very much welcome Abhi, glad to have helped, cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.