Gorilla3D Primative Teachings
Subscribe to Feed:
PHP & Firefox 3 AJAX Image Upload
Friday, August 15, 2008
PHP + Firefox3 AJAX Image Upload
Here is a sample dump of using firefox3's getAsDataURL to push to php and using GD to process it into an image and then save to file.
0 comments
Here is a sample dump of using firefox3's getAsDataURL to push to php and using GD to process it into an image and then save to file.
/* Ajax Functions */ function Ajax(url, options) { if (typeof XMLHttpRequest!='undefined') {var page = new XMLHttpRequest();} else if (window.createRequest) { var page = window.createRequest();} else if (window.ActiveXObject) { var page = new ActiveXObject('MSXML2.XMLHTTP.3.0');} else { alert('Ooops, we failed to process your request. Tell us your browser please!'); } if (page) { if (options.method == 'post') { page.open('POST', url, true); page.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded") } else { page.open('GET', url, true); } page.onreadystatechange = function() { if (page.readyState == 4 && page.status == 200) { if ('function' == typeof options.onComplete) options.onComplete(page.responseText); } } if (options.method == 'post') { page.send(options.data); } else { page.send(null); } } else { alert('There has been a problem processing your request'); } } function writeImage() { var imgdata = $('imagefile').files.item(0).getAsDataURL(); var imgsize = $('imagefile').files.item(0).fileSize; var imgname = $('imagefile').files.item(0).fileName; Ajax("post.image.php", {"method":"post", "data": {"data":imgdata, "size":imgsize, "name":imgname}, "onComplete": function(image) { alert('uploaded'); }}); }
<input type="file" id="imagefile" name="imagefile" onchange="writeImage()"/>
<?php $uploadfile = 'temp.jpg'; //-- Parse the data $img_str = $_POST['data']; $img_str = $img_str[1]; //-- Create image from string $image = imagecreatefromstring($img_str); //-- Save to file imagejpeg($image, $uploadfile, 85); ?>
0 comments
Modular C++ Web Server / Framework
Sunday, August 10, 2008
I am working on a modular cpp web server to allow compile c++ shared / dynamic libraries. This way if anyone is ever wanting to challenge themselves, they can do so by writing a module for the deamon using the framework.
Bare-Bone sample library
Compile the dynamic lib
How does one then use this library on the server, well... I'll eventually make a configuration file, but for now you ave to directly edit the webserver.
That correlates to http://localhost/helloworld and outputs "Hello World from a c++ sample"
0 comments
Bare-Bone sample library
#include <stdio.h> #include "HttpModule.h" class hello : public HttpModule { public: static char *get() { char *temp = "Hello World from a c++ sample"; return temp; } }; // the class factories extern "C" HttpModule* create() { return new hello; } extern "C" void destroy(HttpModule* p) { delete p; }
Compile the dynamic lib
# compile into a shared library g++ -fPIC -c hello.cpp g++ -shared -o libhello.so hello.o # Using g++ on intel mac # g++ -dynamiclib -o libhello.so hello.o
How does one then use this library on the server, well... I'll eventually make a configuration file, but for now you ave to directly edit the webserver.
module_map http_modules [] = { {"/helloworld", "./libhello.so"} };
That correlates to http://localhost/helloworld and outputs "Hello World from a c++ sample"
0 comments
Gorilla Db - (Improved) MySQLi Wrapper
Sunday, August 3, 2008
I've updated my mysqli wrapper to handle binds better and easier to new people trying to use prepared statements. I've also added Non-Filtered binds, because I'll also be release my Table class to help with simple queries you always end up running.
Db is a connection manager, it will use the connection you first create throughout your application. You can continue to call Db:init() and as long as a connection has already been made, you can run queries. Best of all It has prepared statements thanks to Wrapping MySQLi. For documentation and download please visit Gorilla Labs
0 comments
Db is a connection manager, it will use the connection you first create throughout your application. You can continue to call Db:init() and as long as a connection has already been made, you can run queries. Best of all It has prepared statements thanks to Wrapping MySQLi. For documentation and download please visit Gorilla Labs
//-- Prepared Statements // Execute a query $db->prepare('SELECT * FROM blog_entries WHERE id=?')->bind(23)->query(); // or $db->prepare(SELECT * FROM blog_entries WHERE id=?); $db->bind(23); $db->query(); // you can also stack binds $db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?') ->bind(23)->bind('Hello World')->query(); $db->prepare('SELECT * FROM blog_entries WHERE id=? and title=?') $entry = $db->fetchOne(); // you can do can use them all in the same parameter $db->prepare('SELECT * FROM events WHERE name LIKE ? OR name LIKE ? and location LIKE ?') ->bind('%My%', '%Event%', '%San%') ->query(); // you can do can use an array and if they have keys you can assign you ?'s to them $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?') ->query(); // a cleaner example notice they can be in any order but you probably shouldn't $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg2 and location LIKE ?') ->query(); // and yes keys can be used multiple times $db->prepare('SELECT * FROM events WHERE name LIKE ?arg1 OR name LIKE ?arg1 and location LIKE ?') ->query();
0 comments
Wordpress Plugin Development: Not so bad?
Saturday, August 2, 2008
When I had tried Drupal for size the admin area was so complex I'd never recommend it to a sane person. Wordpress has a much more simple admin area, but whats impressed me is how simple their API is. I wish it was more documented, but its given me a good run.
Wordpress's Front-end (What everyone else see) is crap. But its Back-end is not half bad. I get access to their editor, users and so on.
So later this week I'll post a really clean plugin so you can all agree with me :)
0 comments
Wordpress's Front-end (What everyone else see) is crap. But its Back-end is not half bad. I get access to their editor, users and so on.
So later this week I'll post a really clean plugin so you can all agree with me :)
0 comments
Gorilla Db - MySQLi Wrapper
Monday, April 7, 2008
Db has been used in a number of my projects, the main focus of this class is to simplify the overall process of prepared statements. As this was migrated into my work place need for docs and log functions was created.
Db is a connection manager, it will use the connection you first create throughout your application. You can continue to call Db:init() and as long as a connection has already been made, you can run queries. Best of all It has prepared statements thanks to Wrapping MySQLi. For documentation and download please visit Gorilla Labs
0 comments
Db is a connection manager, it will use the connection you first create throughout your application. You can continue to call Db:init() and as long as a connection has already been made, you can run queries. Best of all It has prepared statements thanks to Wrapping MySQLi. For documentation and download please visit Gorilla Labs
0 comments