} else { // Tweak the file size for a generic upload error. $file["size"] = 0; } } // Some problems in uploading result in files which are // zero in size. We asume that people who upload zero byte // files will almost always have problems uploading. We simply // skip 0 byte files here, so after this loop we'll show a // generic upload error if no files were uploaded in the end. if ($file["size"] == 0) { continue; } // Let the file storage API run some upload access checks // (maximum attachment file size and file type). if (!phorum_api_file_check_write_access(array("link" => PHORUM_LINK_EDITOR, "filename" => $file["name"], "filesize" => $file["size"]))) { $PHORUM["DATA"]["ERROR"] = phorum_api_strerror(); break; } // Check if the total cumulative attachment size isn't too large. if ($PHORUM["max_totalattachment_size"] > 0 && $file["size"] + $attach_totalsize > $PHORUM["max_totalattachment_size"] * 1024) { $PHORUM["DATA"]["ERROR"] = str_replace('%size%', phorum_filesize($PHORUM["max_totalattachment_size"] * 1024), $PHORUM["DATA"]["LANG"]["AttachTotalFileSize"]); break; } // Add the file data and user_id to the file info for the hook call. $file["data"] = @file_get_contents($file["tmp_name"]); $file["user_id"] = $PHORUM["user"]["user_id"]; /* * [hook] * before_attach *
// ---------------------------------------------------------------------- // Handle storing a newly uploaded file. // ---------------------------------------------------------------------- if (!empty($_FILES) && is_uploaded_file($_FILES["newfile"]["tmp_name"])) { // Read in the uploaded file. if (!empty($_FILES["newfile"]["size"])) { $fp = fopen($_FILES["newfile"]["tmp_name"], "r"); $file_data = fread($fp, $_FILES["newfile"]["size"]); fclose($fp); } else { $file_data = ""; } // Create the file array for the file storage API. $file = array("user_id" => $PHORUM["user"]["user_id"], "filename" => $_FILES["newfile"]["name"], "filesize" => $_FILES["newfile"]["size"], "file_data" => $file_data, "link" => PHORUM_LINK_USER); // Store the file. if (!phorum_api_file_check_write_access($file) || !phorum_api_file_store($file)) { $PHORUM["DATA"]["ERROR"] = phorum_api_error_message(); } else { $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["FileAdded"]; } } elseif (!empty($_POST["delete"])) { foreach ($_POST["delete"] as $file_id) { if (phorum_api_file_check_delete_access($file_id)) { phorum_api_file_delete($file_id); } } } // ---------------------------------------------------------------------- // Display the files for the current user. // ---------------------------------------------------------------------- $files = $PHORUM['DB']->get_user_file_list($PHORUM["user"]["user_id"]);