Skip to content

Instantly share code, notes, and snippets.

@tmyymmt
Created September 6, 2014 03:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tmyymmt/43971b48414a872b912a to your computer and use it in GitHub Desktop.
puwikiki attach zip /plugin/attach.inc.php.1.5.0.diff
42,43d41
< define('PLUGIN_OPEN_AVOID_DIRECT', FALSE); // TRUE or FALSE
<
160c158
< global $vars, $_attach_messages, $notify, $notify_subject;
---
> global $_attach_messages, $notify, $notify_subject;
190,221d187
< if ($vars['extract_mode'] == 'on') {
< switch (strtolower(substr($file['name'], -4))) {
< case '.zip':
< $efiles = unzip($file['tmp_name']);
< break;
< default:
< die_message('invalid file type');
< }
< if ($efiles === FALSE) {
< return array(
< 'result'=>FALSE,
< 'msg'=>$_attach_messages['err_extract']);
< }
< foreach ($efiles as $efile) {
< $ret = do_upload($page,
< mb_convert_encoding($efile['extname'], SOURCE_ENCODING, 'auto'),
< $efile['tmpname']);
< if (! $ret['result']) {
< unlink($efile['tmpname']);
< }
< }
< return $ret;
< } else {
< return do_upload($page, $file['name'], $file['tmp_name']);
< }
< }
<
< function do_upload($page, $fname, $tmpname)
< {
< global $_attach_messages;
<
< $obj = & new AttachFile($page, $fname);
222a189
> $obj = & new AttachFile($page, $file['name']);
227,236c194,196
< if (is_uploaded_file($tmpname)) {
< if (move_uploaded_file($tmpname, $obj->filename)) {
< chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
< }
< } else {
< if (rename($tmpname, $obj->filename)) {
< chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
< }
< }
<
---
> if (move_uploaded_file($file['tmp_name'], $obj->filename))
> chmod($obj->filename, PLUGIN_ATTACH_FILE_MODE);
>
279,283d238
< if (PLUGIN_OPEN_AVOID_DIRECT && ! strstr($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) {
< header('Location: ' . get_script_uri());
< exit;
< }
<
456d410
< $arc_support = extension_loaded('zip') ? '*.zip,' : '';
469d422
< <br />{$_attach_messages['msg_extract']}:<input type="checkbox" name="extract_mode"> ({$arc_support})
899,945d851
<
< function unzip($upfile)
< {
< if (! extension_loaded('zip')) {
< return FALSE;
< }
< $tmpupfile = tempnam(CACHE_DIR, 'zip_uploaded_');
< if (! move_uploaded_file($upfile, $tmpupfile)) {
< return FALSE;
< }
< if (! ($fp = zip_open($tmpupfile))) {
< return FALSE;
< }
<
< unset($files);
< $cnt = 0;
< while ($entry = zip_read($fp)) {
< if (zip_entry_open($fp, $entry, "rb")) {
< $name = basename(trim(zip_entry_name($entry)));
< $size = zip_entry_filesize($entry);
< if ($name && $size !== 0) {
< $buff = zip_entry_read($entry, $size);
< $tname = tempnam(CACHE_DIR, 'zip_extracted_');
< if (! ($fpw = fopen($tname , 'wb'))) {
< zip_entry_close($entry);
< zip_close($fp);
< foreach ($files as $file) {
< @unlink($file['tmpname']);
< }
< @unlink($tname);
< @unlink($tmpupfile);
< return FALSE;
< }
< fwrite($fpw, $buff, $size);
< fclose($fpw);
< zip_entry_close($entry);
< $files[$cnt]['tmpname'] = $tname;
< $files[$cnt]['extname'] = $name;
< $cnt++;
< }
< }
< }
< zip_close($fp);
< @unlink($tmpupfile);
< return $files;
< }
<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment