Upload a field in php and save it to mysqlPHPcodeif ($ dsql-& gt; ExecuteNoneQuery ($ SQL) {file storage path $ file_path & quot ;.. upload & quot; save the php upload field to mysql
PHP code
If ($ dsql-> ExecuteNoneQuery ($ SQL) {// file storage path $ file_path = ".. /upload/"; // 664 permission: file owner and group User readable and write, other users read-only if (is_dir ($ file_path )! = TRUE) mkdir ($ file_path, 0664); // defines the extended $ ext_arr = array ("gif", "jpg", "jpeg", "png ", "bmp", "txt", "zip", "rar"); // Obtain the file extension $ temp_arr = explode (". ", $ _ FILES [" photo "] [" name "]); $ file_ext = array_pop ($ temp_arr); $ file_ext = trim ($ file_ext ); $ file_ext = strtolower ($ file_ext); // obtain the information of the uploaded file and assign it to the variable $ upfile =$ _ FILES ['photo']; $ photo = $ upfile; // rename the file with the timestamp $ new_name = time (). ". ". $ file_ext; // move the file to the storage directory Move_uploaded_file ($ _ FILES ["photo"] ["tmp_name"], "$ file_path ". $ new_name); // write file storage information to the data table to manage foreach ($ Items as $ key => $ val) {$ val ['price'] = str_replace (", "," ", $ val ['price']); $ dsql-> ExecuteNoneQuery (" insert into '#@__ shops_products' ('aid ', 'id ', 'userid', 'title', 'price', 'buynum') VALUES ('$ val [id]', '$ OrdersId', '$ userid ', '$ val [title]', '$ val [price]', '$ val [buynum]'); ") ;}$ SQL =" INSERT '#@__ Shops_userinfo '('userid', 'id', 'consignee', 'address', 'Zip', 'Tel ', 'Email', 'QQ', 'cphm ', 'T1', 'T2', 'period ', 'der', 'dabal', 'photo', 'scanning') VALUES (' $ userid', '$ OrdersId ', '$ postname',' $ address', '$ zip', '$ Tel',' $ email ',' $ QQ', '$ cphm',' $ t1 ', '$ t2',' $ period ',' $ de', '$ dabh',' $ photo ',' $ scanning ');"; $ dsql-> ExecuteNoneQuery ($ SQL);} else {ShowMsg ("An error occurred while updating the order! ". $ Dsql-> GetError (), "-1"); exit ();}} else {$ SQL = "update' #@__ shops_orders 'set 'cartcount' = '$ cartcount', 'price' = '$ priceCount ', 'IP' = '$ IP', 'stime' =' $ stime ', pid =' $ pid ', paytype =' $ paytype', dprice = '$ dprice ', priceCount = '$ lastpriceCount' WHERE oid = '$ OrdersId' AND userid = '$ userid'; "; if ($ dsql-> ExecuteNoneQuery ($ SQL )) {$ SQL = "update' #@__ shops_userinfo 'set' consignee '=' $ postname', 'address' = '$ address', 'Zip' =' $ zip ', 'tel '=' $ Tel', 'Email '=' $ email ', 'QQ' =' $ QQ', 'cphm' = '$ cphm ', 'T1' = '$ T1', 'T2' =' $ t2', 'period '=' $ period ', 'Des' = '$ de ', 'dabh' = '$ dabh', 'Photo' = '$ photo', 'scanning' = '$ scanning' WHERE oid =' $ OrdersId ';"; $ dsql-> ExecuteNoneQuery ($ SQL);} else {echo $ dsql-> GetError (); exit;} unset ($ SQL );}
Why is the photo field displayed as an Array after the form is submitted instead of the path of the image uploaded? Files can be uploaded and submitted. if a problem occurs in that place, please kindly advise !!!!
------ Solution --------------------
The variable $ photo corresponds to the field photo.
While
$ Photo = $ upfile;
And
$ Upfile = $ _ FILES ['photo'];
Is an array
You should save $ file_path. $ new_name to the photo field.
However, "../" in $ file_path may cause trouble for later use.