0

I want to select a default if my users don't select a file.

I checked if the file input is empty. and I don't know the next steps. here is my code.

PHP:

if ($_FILES['ilyes']['size'] == 0)
{
    // select the default file(name="blanc.jpeg" and the path="../blanc.jpeg")
}

HTML:

<input type="file" name="ilyes">
2
  • 1
    What are you doing with the file once it has been uploaded? Commented Nov 25, 2019 at 11:33
  • Might be this link helps to you stackoverflow.com/a/14458594/4781696 Commented Nov 25, 2019 at 11:40

2 Answers 2

1

You can check file post if it empty set default image

if (!empty($_FILES)) {

      // select the default file(name="blanc.jpeg" and the path="../blanc.jpeg")

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

Comments

0

You can check file is uploaded or not by using below if else condition. if your file is not empty than upload your selected file or if your file is empty upload default image.

if (isset($_FILES['ilyes']) && !empty($_FILES['ilyes']['name']))
{
  //upload your selected file here
}
else
{
 //upload your default file here
}

2 Comments

the problem is that i don't know how to use upload with javascrit
you want to upload file with ajax or simple php?

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.