Php allows you to upload files to a specified folder, store the file path or name to the database. how can this problem be solved? Please help ., HTMLcode & lt; formaction = & quot; method = & quot; post & quot; enctype = & quo php uploads files to a specified folder, and stores the file path or name in the database, how to implement it?
Do you have any experts? Help me.
------ Solution --------------------
HTML code
------ Solution --------------------
Complete database operations:
PHP code
------ Solution --------------------
I want
PHP code
Define (UPLOAD_ROOT, 'Upload folder path'); function fake_random_name ($ string, $ key) {# Pseudo-code generates a pseudo-random file name based on the user name and upload time as the uploaded User name # The decoding condition is that the user name and upload time of the file owner can be determined based on the file name # required the user's key can be extracted from the database for decryption. The key is the first five characters of the user name. # for specific encryption and decryption code implementation, refer to the N methods under the Mcrypt extension of the PHP Standard Extension Library. return $ fake_random_name ;} if (! Is_writbale (UPLOAD_ROOT) {die ('you need chown the dir for your uploading file, make it writable ~ ');} Else {move_uploaded_file ($ _ FILES ['form name from POST'] ['tmp _ name'];/*** this method will automatically call is_upload_file () method to check whether the FILE is uploaded by the valid http rfc1867 protocol * Of course, you can also limit whether it is the legal FILE type you need $ _ FILE [$ _ POST [name] [type], for example, whether it is pdf imgfiles can all be */$ dbh = new mysqli ('localhost ', 'root', 'sa ', 'Your _ db_name '); # The generated file can include the DSN and put it outside the root directory to protect the connection file $ sec_key = substr ($ _ SESSION ['loginname ); # key $ file_name = fake_random_name ($ _ FILES ['form name from POST '] ['tmp _ name'], $ sec_key ); # encrypted name $ q_str = "insert into tb (owner, location) values ($ _ SEESION ['loginname'], UPLOAD_ROOT.DIRECTORYSLASH. $ file_name) ";/SQL $ dbh-> query ($ q_str); if ($ dbh-> num_rows () = 1) echo" Upload successful, details of the inserted database file (encrypted )";}
------ Solution --------------------
Set the file storage path, upload the last file through the move_uploaded_file function, and insert the uploaded file name to the database.
------ Solution --------------------
Learning and splitting