Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

How can I upload multiple pictures to my web page with php?

How can I upload multiple pictures to my web page with php?
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

Dear Marco Gasi,
Thank you very much.

What is the most secure way to do this?

Is this code is enough to secure the server while uploading files?

If this code is basic,
Do you have the more comlex and secure code for image upload?
As far as I know, that code is secure enough. It is basic because, for instance, I sometime prefer to change the picture name, or I want to create thumbnails and so on. Since you are uploading images storing them on the server I don't think there are security risk.
Avatar of BR

ASKER

Thank yo very much Marco Gasi
Avatar of BR

ASKER

Thank you
You're welcome!
Avatar of BR

ASKER

Dear Marco,
Something wrong with the code?

On this bold line, php gives error

$valid_formats = array(
        'jpg',
      'png',
      'gif'
)
if (isset($_FILES['pictures']['name']) && !empty($_FILES['pictures']['name'])){
Did you change the name of your input element?
Avatar of BR

ASKER

I changed nothing, I just copied and pasted the code
What is the error message?
And can you show me your whole script?
Avatar of BR

ASKER

please see attached file, on the line 19 th, there is a problem.

it didn't show the page at all.
upload.php
Avatar of BR

ASKER

I found it :)
its a semicolon
I can't find the semicolon but I'm happy you have found the problem :)
Avatar of BR

ASKER

after this,
$valid_formats = array(
        'jpg',
      'png',
      'gif'
)  
a semicolon was needed
Wooops, I'm sorry!
Hi Braveheartli. I saw you posted another question about the same argument: did something go wrong with my solution?
Avatar of BR

ASKER

Sorry Marco,
I couldn't make it work.

firs it was the button missing? Then I put a submit button, but it didn't upload anyway. I'm sorry. Thank you anyway.
you taught me a lot. ( I learn a lot from you )
Yes, I didn't add the button because I thought the code would have been inserted in an existing form so I wanted only to show you the input element.
Anyway, that's strange because that ia piece of code I extracted by a my working script using in one of my sites...

I saw you prefer to upload each image separately, so I leave that to Julian, but the only thing I can think to is that maybe you don't have created the directory 'uoload' in your server (path is relative), so the upload fails because php doesn't create automatically a directory if this doesn't exist.