0

this action is called when i m upload image:

 header("Expires: 1997年7月26日 05:00:00 GMT");
 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
 header("Cache-Control: no-store, no-cache, must-revalidate");
 header("Cache-Control: post-check=0, pre-check=0", false);
 header("Pragma: no-cache");
 $targetDir = Mage::getBaseDir('media') . DS . 'plupload' ;
 $cleanupTargetDir = true; // Remove old files
 $maxFileAge = 5 * 3600; // Temp file age in seconds
 if (!file_exists($targetDir)) {
 @mkdir($targetDir);
 } 
 if (isset($_REQUEST["name"])) {
 $fileName = $_REQUEST["name"];
 } elseif (!empty($_FILES)) {
 $fileName = $_FILES["file"]["name"];
 } else {
 $fileName = uniqid("file_");
 }
 $_SESSION['file'] = $fileName;
 $filePath = $targetDir . DS . $fileName;
 // Chunking might be enabled
 $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
 $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
 // Remove old temp files 
 if ($cleanupTargetDir) {
 if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
 die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
 }
 while (($file = readdir($dir)) !== false) {
 $tmpfilePath = $targetDir . DS . $file;
 // If temp file is current file proceed to the next
 if ($tmpfilePath == "{$filePath}.part") {
 continue;
 }
 // Remove temp file if it is older than the max age and is not the current file
 if (preg_match('/\.part$/', $file) && (filemtime($tmpfilePath) < time() - $maxFileAge)) {
 @unlink($tmpfilePath);
 }
 }
 closedir($dir);
 } 
 // Open temp file
 if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
 die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
 }
 if (!empty($_FILES)) {
 if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
 die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
 }
 // Read binary input stream and append it to temp file
 if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
 die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
 }
 } else { 
 if (!$in = @fopen("php://input", "rb")) {
 die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
 }
 }
 while ($buff = fread($in, 4096)) {
 fwrite($out, $buff);
 }
 @fclose($out);
 @fclose($in);
 // Check if file has been uploaded
 if (!$chunks || $chunk == $chunks - 1) {
 // Strip the temp .part suffix off 
 rename("{$filePath}.part", $filePath);
 }
 // Return Success JSON-RPC response
 die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');

this action is called when i m click on button:

 $comment = $_POST['comments1'];
 $id = $_SESSION['id'];
 $time = date("Y-m-d h:i:s", Mage::getModel('core/date')->timestamp(time()));
 $conn = Mage::getModel('management/comment');
 $conn->setData('comment',$comment);
 $conn->setData('task_id',$id);
 $conn->setData('time',$time);
 $conn->save();
// $obj = Mage::getModel('management/comment')->getCollection();
 $cid = $conn->getCommentId();
 $file = $_SESSION['img'];
 $fileName = $_SESSION['file'];
 $type = $_SESSION['type'];
 $conn = Mage::getModel('management/file');
 $conn->setData('filename',$fileName);
 $conn->setData('file',$file);
 $conn->setData('type',$type);
 $conn->setData('comment_id',$cid);
 $conn->setData('task_id',$id);
 $conn->save();

In plupload i m upload two or more files n when i m click on button that time i want to store all file in database.

how to store all file in database when i m click on button?

asked Dec 22, 2014 at 12:06
2
  • Here in this question you asked for retrieving and told you succeeded now again you are here asking fro uploading?Without uploading images how did you manage to retrieve? Commented Dec 22, 2014 at 12:31
  • that was succeed but for only single file store in database now i want to store multiple file in database Commented Dec 22, 2014 at 12:36

1 Answer 1

1

Change the code in action when you upload image

 $_SESSION['file'] = $fileName;

write this code:

 if($_SESSION['file'] !=""){
 $fileNameOld = $_SESSION['file'];
 $_SESSION['file'] = $fileNameOld.','.$fileName;
 }
 else{
 $_SESSION['file'] = $fileName;
 }

And in another action write this code after query

 $_SESSION['file'] = "";
answered Dec 23, 2014 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.