Sunday 15 January 2012

php - Uploadify rename more than one file -


I am using uploadify on a project, and I have to change the name of a file to the php script, but if I If more than one file is uploaded at one time then is it unsure to repeat the process?

My PHP script is below ...

  $ targetFolder = '/ img / uploads'; // Token = Verify token = MD5 ('Unique_Salt'. $ _POST ['Timestamp']); If (! Empty ($ _ FILES) & amp; $ _POST ['token'] == $ verification token) {$ tempFile = $ _FILES ['filtered'] ['tmp_name']; $ TargetPath = $ _SERVER ['DOCUMENT_ROOT'] $ TargetFolder; $ FileParts = pathinfo ($ _ files ['philadelphia'] ['name']); $ Unique_hash = hash_hmac ("md5", file_get_contents ($ _ files ['filadata'] ['name']), SLT; $ TargetFile = rtrim ($ target path, '/') '/' $ unique_hash. ' $ _ POST ['userId']. '. '$ FileParts [' extension ']; # $ TargetFile = rtrim ($ target path, '/') '/' $ _FILES ['filedata'] ['name']; // file type $ fileTypes = array valid ('jpg', 'jpeg', 'gif', 'png'); // file extension $ fileParts = pathinfo ($ _ files ['filadata'] ['name']); If (in_array ($ fileParts ['extension'], $ fileTypes) {move_uploaded_file ($ tempFile, $ targetFile); Echo '1'; } Else {echo 'invalid file type.'; }}    

When you use AJAX, You can send a request after one you are used to using a foreach or you send the form at once and use the code given below.

When you send all files together, you will use something like this in your form: name = userfile [] so that you forward the files in this way Can:

  foreach ($ file $ as $ FILES) {$ uploadfile = $ uploaddir basename ($ file ['name']); If (! Move_uploaded_file ($ file ["tmp_name"], $ uploadfile)) {echo set_ e ('error', 'image ['. $ I.] not uploaded '', ''); }}    

No comments:

Post a Comment