Hi Guys
I have been extracting zip files and uploading them successfully with PclZip Library.However i want to rename the extracted files using some random string generator on the fly before placing them in my 'images' folder
On the site they said that a callback function can be used to rename the files but its not working
Referance
http://www.phpconcept.net/pclzip/user-guide/18
Here is code
if(move_uploaded_file($file_tmp, $target_path)) {
$zip = new PclZip($target_path);
$zip->extract(PCLZIP_OPT_PATH, $destination_path,
PCLZIP_OPT_REMOVE_ALL_PATH,
PCLZIP_CB_PRE_EXTRACT, "zipPreExtractCallBack");
unlink($target_path);
$message = "Your .zip file was uploaded and unpacked.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
Now the most important thing - the function
function zipPreExtractCallBack($p_event, &$p_header) {
$info = pathinfo($p_header['filename']);
// limit the unzipped images
if ($info['extension'] == 'jpeg' || $info['extension'] == 'jpg' || $info['extension'] == 'gif' || $info['extension'] == 'png'|| $info['extension'] == 'bmp' ) {
$get_host_iconv_encode = iconv_get_encoding("internal_encoding");
$get_file_mb_encode = mb_detect_encoding( $info['basename'] );
$p_header['filename'] = iconv( $get_host_iconv_encode , $get_file_mb_encode.'//TRANSLIT//IGNORE' , $p_header['filename'] );
return 1;
}
// other file extensions will not be unzipped
else return 0;
}
I want the function to auto-rename images name before saving them in $destination_path .
Can anyone of you help me with this library
Insert something similar in code
$random_code = random_gen(5);
$file_name = $random_code.'.'.$file['extension'];
Long Live DaniWeb
Thanks