Skip to content
Browse files

Uploaded widget, added upload route, add module to process uploads

  • Loading branch information...
1 parent 3171239 commit 39f1c5c87b4808c61dc553a83d2f7ff2553dde3f Joshua Estes committed Nov 23, 2011
View
16 README
@@ -0,0 +1,16 @@
+sfPluploadPlugin
+================
+
+Allows you to use plupload with symfony. See http://www.plupload.com/ for info
+on Plupload.
+
+Plupload version included: 1.5.1.1
+
+Installation
+------------
+
+ # settings.yml
+ all:
+ .settings:
+ enabled_modules:
+ - sfPlupload
View
9 config/sfPluploadPluginConfiguration.class.php
@@ -17,5 +17,14 @@ class sfPluploadPluginConfiguration extends sfPluginConfiguration
*/
public function initialize()
{
+ $this->dispatcher->connect('routing.load_configuration', array($this, 'listenToRoutingLoadConfigurationEvent'));
+ }
+
+ public function listenToRoutingLoadConfigurationEvent(sfEvent $event)
+ {
+ $r = $event->getSubject();
+ $r->prependRoute('sf_plupload_upload', new sfRoute('/sfPlupload/upload', array(
+ 'module' => 'sfPlupload',
+ 'action' => 'upload')));
}
}
View
2 lib/widget/sfWidgetFormPlupload.class.php
@@ -27,7 +27,7 @@ public function render($name, $value = null, $attributes = array(), $errors = ar
$(function(){
$('#uploader').pluploadQueue({
runtimes: 'gears,flash,silverlight,browserplus,html5',
- url: 'upload.php',
+ url: '/sfPlupload/upload',
max_file_size: '300mb',
chunk_size: '1mb',
flash_swf_url: '/sfPluploadPlugin/plupload.flash.swf',
View
111 modules/sfPlupload/actions/actions.class.php
@@ -0,0 +1,111 @@
+<?php
+
+/**
+ * sfPlupload actions.
+ *
+ * @package video.iostudio.com
+ * @subpackage sfPlupload
+ * @author Your name here
+ * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
+ */
+class sfPluploadActions extends sfActions
+{
+
+ /**
+ * Process a file upload
+ *
+ * @param sfWebRequest $request
+ */
+ public function executeUpload(sfWebRequest $request)
+ {
+ $this->getResponse()->setHttpHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
+ $this->getResponse()->setHttpHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT');
+ $this->getResponse()->setHttpHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
+ $this->getResponse()->setHttpHeader('Cache-Control', 'post-check=0, pre-check=0', false);
+ $this->getResponse()->setHttpHeader('Pragma', 'no-cache');
+
+ set_time_limit(5 * 60);
+
+ $targetDir = sfConfig::get('sf_upload_dir');
+
+ $chunk = $request->getParameter('chunks', 0);
+ $chunks = $request->getParameter('chunk', 0);
+ $fileName = $request->getParameter('name','');
+
+ $fileName = preg_replace('/[^\w\._]+/', '', $fileName);
+
+ // Make sure the fileName is unique but only if chunking is disabled
+ if($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName))
+ {
+ $ext = strrpos($fileName, '.');
+ $fileName_a = substr($fileName, 0, $ext);
+ $fileName_b = substr($fileName, $ext);
+
+ $count = 1;
+ while(file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b))
+ $count++;
+
+ $fileName = $fileName_a . '_' . $count . $fileName_b;
+ }
+
+ // Look for the content type header
+ $contentType = '';
+ if(isset($_SERVER["HTTP_CONTENT_TYPE"]))
+ $contentType = $_SERVER["HTTP_CONTENT_TYPE"];
+
+ if(isset($_SERVER["CONTENT_TYPE"]))
+ $contentType = $_SERVER["CONTENT_TYPE"];
+
+ // Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
+ if(strpos($contentType, "multipart") !== false)
+ {
+ if(isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name']))
+ {
+ // Open temp file
+ $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
+ if($out)
+ {
+ // Read binary input stream and append it to temp file
+ $in = fopen($_FILES['file']['tmp_name'], "rb");
+
+ if($in)
+ {
+ while($buff = fread($in, 4096))
+ fwrite($out, $buff);
+ } else
+ die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
+ fclose($in);
+ fclose($out);
+ @unlink($_FILES['file']['tmp_name']);
+ } else
+ die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
+ } else
+ die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
+ } else
+ {
+ // Open temp file
+ $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab");
+ if($out)
+ {
+ // Read binary input stream and append it to temp file
+ $in = fopen("php://input", "rb");
+
+ if($in)
+ {
+ while($buff = fread($in, 4096))
+ fwrite($out, $buff);
+ } else
+ die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
+
+ fclose($in);
+ fclose($out);
+ } else
+ die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
+ }
+
+ // Return JSON-RPC response
+ die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
+ return sfView::NONE;
+ }
+
+}

0 comments on commit 39f1c5c

Please sign in to comment.
Something went wrong with that request. Please try again.