php - File Upload with Description -


By uploading each file to my server, I have received a simple file upload for my website, however, Users want to upload the file to upload the file and upload the date of the upload to the MySQL database.

I can fix all this, which I can list files or lists details and dates separately, ideally I will list it all the dates, descriptions and file titles in a table But I'm not sure how I am linking the file link to the details.

If I am not happy about it, I am very clear about it again.

code: adddocument.php

  form action = "upload.php" method = "post" enctype = "multiparty / form-data" & gt; & Lt; P & gt; Date: & lt; Br> & Lt; Input type = "text" name = "docDate" id = "datepicker" & gt; & Lt; / P & gt; & Lt; P & gt; Details: (max 100 characters): & lt; Br> & Lt; Textarea name = "description" rows = "4" cols = "50" maximum length = "100" & gt; & Lt; / Textarea & gt; & Lt; / P & gt; & Lt; P & gt; The file you want to upload: & lt; Br> & Lt; Input type = "file" name = "file" & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "submit" & gt; & Lt; / P & gt; & Lt; / Form & gt;  

Upload.php

  & lt ;? Php $ name = $ _FILES ['file'] ['name']; $ Extension = strtolower (substr ($ name, strokes ($ name, '.') + 1)); $ Size = $ _FILES ['file'] ['size']; $ Max_sage = 20 9 7152; $ Type = $ _FILES ['file'] ['type']; $ Tmp_name = $ _FILES ['file'] ['tmp_name']; If (isset ($ name) {if ((empty ($ name)} {if ($ extension == 'jpg' || $ extension == 'jpeg' || $ extension == 'pdf' || $ extension == 'Docs' || $ Extension ==' Doctor ') {If ($ size & lt; = $ max_size) {$ location =' Upload ''; if (move_uploaded_file ($ tmp_name, $ location. $ Name)) {Echo 'File is uploaded';} Else {echo 'was an error';}} Else {echo 'file should be 2MB or less';}} Else {dumb 'invalid file type';}} else { Echo 'please select a file'.}}? & Gt; & lt ;? php $ con = mysqli_connect ("localhost", "pitesmem_brody", "brody", "pitesmem_brody"); $ sql = " Enter the documents (DOCKADET, DETAILS) value ('$ _ POST [DocDate]', '$ _ POST [details]') "; Mysqli_query ($ conn, $ sql); / * committed transaction * / if (! Mysqli_commit $ Con) {Print ("Transaction failed unsuccessful \ n"); Exit ();} / * Close connection * / mysqli_close ($ con);? & Gt;  

Currently I list all the files uploaded using this code.

   & # 39; & # 39; }}}? & Gt;  

You know where the file is ( $ location. $ Name < / Code>), store that information in the database table as well as name and description.

Use that file to generate the URL.


Comments