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.

Bhavik
  • 92
  • 2
  • 5
  • 12

5 Answers5

3

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

deceze
  • 510,633
  • 85
  • 743
  • 889
3

You need to do:

<form action="someaction.php" method="post" enctype="multipart/form-data">
Adam
  • 1,371
  • 2
  • 11
  • 12
2

Add this to your form tag:

enctype = multipart/form-data
Mayank Sharma
  • 844
  • 7
  • 21
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.

SAID Ali
  • 11
  • 2
1

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

Tony Stark
  • 8,064
  • 8
  • 44
  • 63