How to delete one uploaded temp file but keep others from the same form?
Jamroom Developers
function jrUjPano_form_validate_exit_listener($_data, $_user, $_conf, $_args, $event)
{
global $_post;
if (isset($_post['upload_token'])) {
$_fl = jrCore_get_uploaded_media_files('jrGallery', 'gallery_image');
if ($_fl && is_array($_fl) && isset($_fl[0])) {
foreach ($_fl as $_img) {
// check it is 2:1
$_tmp = getimagesize($_img);
$w = (int) $_tmp[0];
$h = (int) $_tmp[1];
if ($w / $h !== 2) {
// it isn't an equirectangular image
//jrCore_delete_upload_temp_directory($_post['upload_token']);
unlink($_img);
unlink($_img .'.tmp');
jrCore_set_form_notice('notice', "Invalid Equirectangular Image");
jrCore_form_field_hilight('gallery_image');
jrCore_form_result();
}
else {
}
}
}
}
return $_data;
}
unlink($_img);
unlink($_img .'.tmp');
/**
* Get media files that have been uploaded from a form
* NOTE: $module is no longer used in this function, but was
* at one time so is left there for backwards compatibility
* @param string $module Module Name to check file for
* @param string $file_name Name of file field in form
* @return mixed
*/
function jrCore_get_uploaded_media_files($module = null, $file_name = null){
global $_post;
if (isset($_post['upload_token']{0})) {
$dir = jrCore_get_upload_temp_directory($_post['upload_token']);
if (is_dir($dir)) {
if (is_null($file_name)) {
$_tmp = glob("{$dir}/*.tmp", GLOB_NOSORT);
}
else {
$_tmp = glob("{$dir}/*_{$file_name}.tmp", GLOB_NOSORT);
}
if ($_tmp && is_array($_tmp) && count($_tmp) > 0) {
foreach ($_tmp as $k => $v) {
$_tmp[$k] = substr($v, 0, strlen($v) - 4);
}
sort($_tmp, SORT_NATURAL);
return $_tmp;
}
}
}
return false;
}