Image upload to server using html and php -


I am new and experimenting with web development.

I am trying to upload an image to a server using the following html and php code.

  & lt; Form action = "upload_image.php" method = "post" enctype = "multipart / form-data" & gt; Upload images from source: & lt; Input type = "file" name = "picture" & gt; & Lt; Input type = "submit" name = "upload" value = "upload image" & gt; & Lt; / Form & gt; & Lt ;? Php if (isset ($ _ POST ['Upload'])) {$ image_name = $ _FILES ['image'] ['name']; $ Image_type = $ _FILES ['image'] ['type']; $ Image_size = $ _FILES ['image'] ['size']; $ Image_tmp_name = $ _FILES ['image'] ['tmp_name']; If ($ image_name = '') {"& lt; script> warnings (select a picture to upload ') & lt; / script & gt;"; Go out(); } Else move_uploaded_file ($ image_tmp_name, "/ pictures / $ image_name"); "Your label picture has been sent"; "/ Pictures /". $ _FILES ["file"] ["$ image_name"]; "stored in: " . "Pictures /". $ _FILES ["file"] ["$ image_name"]; }? & Gt;  

On choosing a file, it opens a new web page 'upload_image.php'.

No file is being uploaded and it is being saved on the server.

I am sure that I am making the most basic errors, but I do not know what it is!

Thank you for the help

This is most likely because you are root relative You do not have the necessary permissions to save the path or folder that you are using. However, I see that you are not validating the type of file uploaded to the server. Use the following snippet to validate the file type and size:

  $ allowed xray = array ("gif", "jpeg", "jpg", "png"); $ Temp = Explosion (".", $ _FILES ["file"] ["name"]); $ Extension = end ($ temp); If (($ $ _FILES ["file"] ["type"] == "image / gif") ($ _FILES ["file"] ["type"] == "image / JPEG") || ($ $ _FILES ["file"] ["type"] == "image / JPG") ($ _FILES ["file"] ["type"] == "image / PJPAG") ($ _FILES ["file" ] ["Type"] == "image / x-png") ($ _FILES ["file"] ["type"] == "image / PNG")) & amp; amp; amp; amp; Amp; $$ _FILES ["file"] ["size"] <20 97152) // limit file size is 2MB & amp; Amp; Amp; & Amp; In_array ($ Extension, $ Permission Received)) code to execute {// code} if other {// code file is not allowed} execute}  

_POST For more information about file handling using:


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -