php - What does $ _FILES ["upload"] ["tmp_name"] -


i have general question php, can't understand $ _files ["upload"] ["tmp_name"], why should upload file tmp folder, , not direclty permanent folder? read, have nice day!

the php interpreter puts uploaded file in temporary directory using generated name , stores path in $_files['...']['tmp_name'] before running php script.

you can use is_uploaded_file() make sure content of $_files['...']['tmp_name'] indeed path of uploaded file (and not spoofed somehow in request) use move_uploaded_file() put file on final destinations.

or can process content of file without moving it, in case don't need store file.

either way, when script ends interpreter removes temporary files created store uploaded content.

the code looks like:

if (is_uploaded_file($_files['abc']['tmp_name'])) {     // generate path store file     // depending on expected file type can use getimagesize()      // or mime_content_type() find correct file extension     // , various ways generate unique file name (to not overwrite     // file existing in storage directory)     $finalpath = '...';      if (move_uploaded_file($_files['abc']['tmp_name'], $finalpath)) {         // uploaded , processed.     } else {         // cannot move file; maybe there permissions issue         // or destination directory doesn't exist.     } } else {     // upload failed.     // check value of $_files['abc']['error'] find out why     // (usually no file uploaded or file large). } 

read php way handle file uploads.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -