3

i m trying to update images using GET method

user_form.php

<form action='upload.php' method='get'>  
  <input type='file' name='user_img' />
  <input type='text' name='username' />
  <input type='submit' name='update' value='update'>
</form>

upload.php

if(isset($_GET['update']))
{
  echo 'username: '.$_GET['username'];
  echo 'file name: '.$_FILES['user_img']['tmp_name'];
}

i m getting correct value for username, however, blank value for filename.

can anyone please let me know if we can use $_FILES variable for GET method? if yes then please point out where m i going wrong in the above sample code. thank you.

0

5 Answers 5

3

You cannot upload files using a GET HTTP request. Files are sent in the HTTP body, which requires a POST or PUT request.

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

1 Comment

+1 - really? I don't know that?
3

You need to do:

<form action="someaction.php" method="post" enctype="multipart/form-data">

Comments

2

Add this to your form tag:

enctype = multipart/form-data

2 Comments

Refer this and you will learn: w3schools.com/php/php_file_upload.asp
+1 - like <form action="upload.php" method="get" enctype = "multipart/form-data" >
1

You should send your form by post method and specify that this form will have a file

<form action='' method="post" enctype="multipart/form-data"> 
  <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> 
  <input type='file' name='user_img' />
  <input type='text' name='username' />
  <input type='submit' name='update' value='update'>
</form>

It is also preferable for reasons of security and performance to indicate the maximum size of files to be sent.

Comments

1

You need to add enctype = multipart/form-data in a form if you want to upload /use files.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.