From: Jason Woofenden Date: Tue, 5 Oct 2010 20:56:14 +0000 (-0400) Subject: make metaform support file uploads X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=f13c842a97d0e1b67fb8f9599be48159f9d2d9ab make metaform support file uploads --- diff --git a/metaform.php b/metaform.php index 3e8c380..e66a477 100644 --- a/metaform.php +++ b/metaform.php @@ -51,6 +51,7 @@ $GLOBALS['types'] = array( 'delete' => array('checkbox', 'yesno', 'n/a'), 'image' => array('image', 'oneline', 'varchar(120)'), 'thumb' => array('image', 'oneline', 'varchar(240)'), + 'file' => array('file', 'oneline', 'varchar(100)'), 'submit' => array('submit', 'oneline', 'n/a') ); @@ -200,7 +201,7 @@ function view_sql() { function find_always_field($fields) { foreach($fields as $field) { list($name, $type, $input, $format, $sql) = $field; - if($input != 'submit' && $input != 'image' && $input != 'checkbox' && $input != 'radio') { + if($input != 'submit' && $input != 'image' && $input != 'file' && $input != 'checkbox' && $input != 'radio') { return $name; } } @@ -231,7 +232,7 @@ function make_html($whole_file = true) { $tem->show('row'); } - if($input == 'image' && !$uploads_output_already) { + if(($input == 'image' || $input='file') && !$uploads_output_already) { $tem->show('uploads'); $tem->set('enctype_attr', '" enctype="multipart/form-data'); $uploads_output_already = true; @@ -377,12 +378,11 @@ function make_php() { } $tem->show('image_settings'); $tem->show('image_upload'); - if(!$image_included_yet) { - $tem->show('image_include'); - $tem->show('upload_max'); - $tem->show('upload_settings'); - $image_included_yet = true; - } + $has_uploads = true; + } else if($input == 'file') { + $tem->show('file_settings'); + $tem->show('file_upload'); + $has_uploads = true; } else { if($input == 'html') { $has_html_editors = true; @@ -401,6 +401,12 @@ function make_php() { } } } + if($has_uploads) { + $tem->show('uploads_include'); + $tem->show('upload_max'); + $tem->show('upload_settings'); + $image_included_yet = true; + } if($has_html_editors) { $tem->show('show_extra_headers'); diff --git a/metaform/template.html b/metaform/template.html index 93702c3..613013e 100644 --- a/metaform/template.html +++ b/metaform/template.html @@ -79,6 +79,8 @@
~caption html~
+
+
~caption html~
~caption html~
diff --git a/metaform/template.php b/metaform/template.php index 6ae0602..daf23ed 100644 --- a/metaform/template.php +++ b/metaform/template.php @@ -25,6 +25,8 @@ define('~file_name upper~_DB_FIELDS', '~db_fields~'); # Set this to the path to your uploads directory. It can be relative to the # location of this script. IT MUST END WITH A SLASH $GLOBALS['upload_directory'] = 'uploads/'; + +$GLOBALS['~name~_file_name'] = uniqid() . getmypid() . '.txt'; # comment this out to use uploader's filename $GLOBALS['~name~_max_width'] = '400'; $GLOBALS['~name~_max_height'] = '400'; @@ -37,7 +39,7 @@ require_once('code/wfpl/template.php'); require_once('code/wfpl/format.php'); require_once('code/wfpl/messages.php'); require_once('code/wfpl/email.php'); -require_once('code/db_connect.php'); +require_once('code/db_connect.php'); require_once('code/wfpl/upload.php'); function ~file_name~_get_fields() { @@ -52,6 +54,19 @@ function ~file_name~_get_fields() { } else { $data['~name~'] = format_image_w_h_thumb_w_h($_REQUEST['old_~name~']); } + } + $~name~_filename_tmp = $GLOBALS['~name~_file_name']; + if(!$~name~_filename_tmp) { + $~name~_filename_tmp = format_filename($_REQUEST['~name~']); + } + if($_FILES['~name~'] && $_FILES['~name~']['error'] == 0) { + $data['~name~'] = save_uploaded_file('~name~', $GLOBALS['upload_directory'] . $~name~_filename_tmp); + } else { + if($_REQUEST['delete_~name~'] == 'Yes') { + $data['~name~'] = ''; + } else { + $data['~name~'] = format_path($_REQUEST['old_~name~']); + } } return $data;