function file_replace() { global $txpcfg, $extensions, $txp_user, $file_base_path; extract($txpcfg); $id = gps('id'); $rs = safe_row('filename', 'txp_file', "id='{$id}'"); if (!$rs) { file_list(messenger(gTxt('invalid_id'), $id, '')); return; } extract($rs); $file = file_get_uploaded(); $name = file_get_uploaded_name(); if ($file === false) { // could not get uploaded file file_list(gTxt('file_upload_failed') . " {$name} " . upload_get_errormsg($_FILES['file']['error'])); return; } if (!$filename) { file_list(gTxt('invalid_filename')); } else { $newpath = build_file_path($file_base_path, $filename); if (is_file($newpath)) { rename($newpath, $newpath . '.tmp'); } if (!shift_uploaded_file($file, $newpath)) { safe_delete("txp_file", "id='{$id}'"); file_list($newpath . sp . gTxt('upload_dir_perms')); // rename tmp back rename($newpath . '.tmp', $newpath); // remove tmp upload unlink($file); } else { file_set_perm($newpath); file_edit(messenger('file', $name, 'uploaded'), $id); // clean up old if (is_file($newpath . '.tmp')) { unlink($newpath . '.tmp'); } } } }
function file_replace() { global $txpcfg, $extensions, $txp_user, $file_base_path; extract($txpcfg); $id = assert_int(gps('id')); $rs = safe_row('filename', 'txp_file', "id = {$id}"); if (!$rs) { file_list(messenger(gTxt('invalid_id'), $id, '')); return; } extract($rs); $file = file_get_uploaded(); $name = file_get_uploaded_name(); if ($file === false) { // could not get uploaded file file_list(gTxt('file_upload_failed') . " {$name} " . upload_get_errormsg($_FILES['thefile']['error'])); return; } if (!$filename) { file_list(gTxt('invalid_filename')); } else { $newpath = build_file_path($file_base_path, $filename); if (is_file($newpath)) { rename($newpath, $newpath . '.tmp'); } if (!shift_uploaded_file($file, $newpath)) { safe_delete("txp_file", "id = {$id}"); file_list($newpath . sp . gTxt('upload_dir_perms')); // rename tmp back rename($newpath . '.tmp', $newpath); // remove tmp upload unlink($file); } else { file_set_perm($newpath); if ($size = filesize($newpath)) { safe_update('txp_file', 'size = ' . $size . ', modified = now()', 'id = ' . $id); } $message = gTxt('file_uploaded', array('{name}' => htmlspecialchars($name))); file_edit($message, $id); // clean up old if (is_file($newpath . '.tmp')) { unlink($newpath . '.tmp'); } } } }
function file_replace() { global $txp_user, $file_base_path; $id = assert_int(gps('id')); $rs = safe_row('filename, author', 'txp_file', "id = {$id}"); if (!$rs) { file_list(array(messenger(gTxt('invalid_id'), $id), E_ERROR)); return; } extract($rs); $filename = sanitizeForFile($filename); if (!has_privs('file.edit') && !($author === $txp_user && has_privs('file.edit.own'))) { require_privs(); } $file = file_get_uploaded(); $name = file_get_uploaded_name(); if ($file === false) { // Could not get uploaded file. file_list(array(gTxt('file_upload_failed') . " {$name} " . upload_get_errormsg($_FILES['thefile']['error']), E_ERROR)); return; } if (!$filename) { file_list(array(gTxt('invalid_filename'), E_ERROR)); } else { $newpath = build_file_path($file_base_path, $filename); if (is_file($newpath)) { rename($newpath, $newpath . '.tmp'); } if (!shift_uploaded_file($file, $newpath)) { safe_delete("txp_file", "id = {$id}"); file_list(array($newpath . sp . gTxt('upload_dir_perms'), E_ERROR)); // Rename tmp back. rename($newpath . '.tmp', $newpath); // Remove tmp upload. unlink($file); } else { file_set_perm($newpath); update_lastmod('file_replaced', compact('id', 'filename')); if ($size = filesize($newpath)) { safe_update('txp_file', 'size = ' . $size . ', modified = now()', 'id = ' . $id); } file_edit(gTxt('file_uploaded', array('{name}' => $name)), $id); // Clean up old. if (is_file($newpath . '.tmp')) { unlink($newpath . '.tmp'); } } } }