Permalink
Browse files

change preloaded images, no longer pushes image data into db, just us…

…es URL instead
  • Loading branch information...
1 parent 3a809c4 commit 96360c64ed06440f5b3f0a978cacd92f0f55e5f5 Dave Whiteland committed Mar 24, 2011
Showing with 30 additions and 17 deletions.
  1. +8 −0 phplib/microsites.php
  2. +22 −17 web/ref-picture.php
View
@@ -264,6 +264,14 @@ function microsite_preloaded_images($key){
return array();
}
+/* microsite_preloaded_image_url()
+ * args: filename of image
+ * Returns; URL of preloaded image
+ */
+function microsite_preloaded_image_url($filename){
+ return rtrim(OPTION_PB_PRELOADED_IMAGES_URL, '/'). '/' . $filename;
+}
+
/* microsite_picture_extra_form()
* Adds an extra form to the picture upload form -- specifically, for Barnet, adds the preloaded images input
*/
View
@@ -67,7 +67,8 @@
// Upload picture
function upload_picture() {
global $picture_upload_allowed, $picture_size_limit, $picture_dimension_limit, $pledge;
-
+ $picture_url = "";
+ $confirm_msg = "";
if (get_http_var('removepicture')) {
db_query("update pledges set picture = null where ref = ?",
array($pledge->ref()));
@@ -77,13 +78,15 @@ function upload_picture() {
return true;
}
- if (microsite_preloaded_images(0) && $preloaded_id = get_http_var('preloaded_image')){
+ if (microsite_preloaded_images(0) && $preloaded_id = get_http_var('preloaded_image')) {
preg_match('/\.(\w+)$/', $preloaded_id, $matches);
- $ext = $matches[1]; # loads $ext with the file extension (assume internal files have sensible extensions)
- $tmp_name = OPTION_PB_PRELOADED_IMAGES_DIR . $preloaded_id;
- if (! file_exists($tmp_name)){
+ $ext = $matches[1]; # loads $ext with the file extension (assume internal files have sensible extensions)
+ # check file exists -- basic validation
+ if (! file_exists(OPTION_PB_PRELOADED_IMAGES_DIR . $preloaded_id)){
return "There was an internal error: couldn't find $preloaded_id";
}
+ $picture_url = microsite_preloaded_image_url($preloaded_id);
+ $confirm_msg = _("Thanks for selecting a picture for the pledge. You can see below what it now looks like.");
} else {
if (!array_key_exists('userfile', $_FILES))
@@ -152,25 +155,27 @@ function upload_picture() {
imagejpeg($dest, $tmp_name);
$ext = "jpeg";
}
- }
- $base_name = $pledge->ref() . "." . $ext;
- $picture_contents = file_get_contents($tmp_name);
- if (!$picture_contents)
- err("Failed to read file into memory");
-
- db_query("delete from picture where filename = ?", $base_name);
- db_query_literal("
- insert into picture (filename, data)
- values ('$base_name', '" . pg_escape_bytea($picture_contents) . "')");
+ $base_name = $pledge->ref() . "." . $ext;
+ $picture_contents = file_get_contents($tmp_name);
+ if (!$picture_contents)
+ err("Failed to read file into memory");
+
+ db_query("delete from picture where filename = ?", $base_name);
+ db_query_literal("
+ insert into picture (filename, data)
+ values ('$base_name', '" . pg_escape_bytea($picture_contents) . "')");
+ $picture_url = OPTION_BASE_URL . "/pics/$base_name";
+ $confirm_msg = _("Thanks for uploading your picture to the pledge. You can see below what it now looks like.");
+ }
db_query("
update pledges
set picture = ?,
changetime = ms_current_timestamp()
where ref = ?",
- OPTION_BASE_URL . "/pics/$base_name", $pledge->ref());
+ $picture_url, $pledge->ref());
db_commit();
- print _("Thanks for uploading your picture to the pledge. You can see below what it now looks like.");
+ print $confirm_msg;
$pledge = new Pledge($pledge->ref());
return true;
}

0 comments on commit 96360c6

Please sign in to comment.