-1

I have a problem

I have a file type input tag that goest like this:

<input type="file" name="imageupload" id="imageupload" value="<?php $imagefile?>">

I have a PHP file that fetch the file name of the image uploaded in the file input tag and my code goes like this:

//Declare the file input tag
$imagefile = trim($_POST['imageupload']);
echo "$imagefile";

I get an error in this part, the declaration part, it says "Notice: Undefined index: imagefile".

Everything works fine if I select an image but if I don't select an image the error shows up.

I would like to assign a default value to the file input tag let say "default.jpg" if user leave it empty or null. I got the condition like this:

if($_FILES['imageupload']['name'] == "" || if($_FILES['imageupload']['size'] == 0) {
$imagefile = trim("default.jpg");
}

then

echo "$imagefile";

I hope my question is specific enough, Please help and thank you.

1 Answers1

0

You can do this to get saved from that error

if(isset($_POST['imageupload']))
{
  $imagefile = trim($_POST['imageupload']);
  echo "$imagefile";
}
else
{
  $imagefile = 'default.jpg';
}
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Yeah I did it that way :D thank you for your solution. It is now sorted out. – Jagmok Dugmok Aug 26 '15 at 02:07
  • You are most welcome. :) You can say thanks by upvoting the answer. – Mohit S Aug 26 '15 at 02:08
  • By the way I did the best I could to make my post more clearer but still I got a -1 and maybe this is my last post coz definitely I am going to be blocked from asking questions. Even so still thanks for the answers :) – Jagmok Dugmok Aug 26 '15 at 02:10
  • 1
    @JagmokDugmok: It is not about convincing you to be on SO. but let me tell you in the start you might feel like the moderators are little more strict than they need to be. But that is the only reason why this website has standards. I am sure when ever we face any programming issue and search on the google. If we see a SO link we already know that our issue is resolved. So Just wait and watch you would love it. – Mohit S Aug 26 '15 at 02:14