<? Php // Upload processing Class Ata_Controller_Action_Helper_Upload extends Zend_Controller_Action_Helper_Abstract { // Notification csv file Public function MsgCsv (& $ source, $ succdata, $ errdata ){ // Original cvs retained // File storage directory $ PublicPath = realpath (APPLICATION_PATH. "/../public/upload ").'/'; $ CsvPath = "msgcsv/". date ('Y'). '/'. date ('M ')."/"; $ Path = $ publicPath. $ csvPath; // Create a directory $ This-> mkdirs ($ path ); // The uniqid () function generates a unique ID based on the current time in microseconds. Uniqid () $ Filename = uniqid (); // Obtain the file extension $ Ext = pathinfo ($ source ['name'], PATHINFO_EXTENSION ); // Create an empty file, directory, file name, and extension $ Filepath = $ path. $ filename. '_ org.'. $ ext; // Move_uploaded_file () to move the uploaded file to the new location Move_uploaded_file ($ source ['tmp _ name'], $ filepath ); // Create a correct csv file $ Content = ''; // Create an empty file, directory, file name, and extension $ Succfile = $ path. $ filename. '_ succ.'. $ ext; // Write $ succdata into $ content; Foreach ($ succdata as $ row ){ // The connection string is equivalent to $ content = $ content. $ row. "n" $ Content. = $ row. "n "; } $ Content = trim ($ content, "n "); // File_put_contents (), write a string to the file File_put_contents ($ succfile, $ content ); // Error csv creation $ Content = ''; $ Errfile = $ path. $ filename. '_ err.'. $ ext; Foreach ($ errdata as $ row ){ $ Content. = $ row. "n "; } $ Content = trim ($ content, "n "); File_put_contents ($ errfile, $ content ); // Return three objects (used to view the failure list and write the successful list content to the hidden domain and pass it to the database) Return array ( 'Orginal' => $ csvPath. $ filename. '_ org.'. $ ext, 'Success' => $ csvPath. $ filename. '_ succ.'. $ ext, 'Error' => $ csvPath. $ filename. '_ err.'. $ ext ); } // Delete an object // Obtain the prefix name of the csv file Public function rmMsgCsv ($ path ){ // $ Prefix: Get the prefix name of the csv file $ Prefix = str_replace('_succ.csv ', '', $ path ); // Delete three objects Unlink(your prefix.'_org.csv '); Unlink(your prefix.'_succ.csv '); Unlink(your prefix.'_err.csv '); } Public function mkdirs ($ dir, $ mode = 0777 ){ Return is_dir ($ dir) or ($ this-> mkdirs (dirname ($ dir) and mkdir ($ dir, $ mode )); } } |