1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Dataflow_Model_Convert_Adapter_Http extends Mage_Dataflow_Model_Convert_Adapter_Abstract
36: {
37:
38: public function load()
39: {
40: if (!$_FILES) {
41: ?>
42: <form method="POST" enctype="multipart/form-data">
43: File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
44: </form>
45: <?php
46: exit;
47: }
48: if (!empty($_FILES['io_file']['tmp_name'])) {
49: $this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
50: }
51: return $this;
52: }
53:
54: public function save()
55: {
56: if ($this->getVars()) {
57: foreach ($this->getVars() as $key=>$value) {
58: header($key.': '.$value);
59: }
60: }
61: echo $this->getData();
62: return $this;
63: }
64:
65:
66: public function loadFile()
67: {
68: if (!$_FILES) {
69: ?>
70: <form method="POST" enctype="multipart/form-data">
71: File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
72: </form>
73: <?php
74: exit;
75: }
76: if (!empty($_FILES['io_file']['tmp_name'])) {
77: $uploader = new Mage_Core_Model_File_Uploader('io_file');
78: $uploader->setAllowedExtensions(array('csv','xml'));
79: $path = Mage::app()->getConfig()->getTempVarDir().'/import/';
80: $uploader->save($path);
81: if ($uploadFile = $uploader->getUploadedFileName()) {
82: $session = Mage::getModel('dataflow/session');
83: $session->setCreatedDate(date('Y-m-d H:i:s'));
84: $session->setDirection('import');
85: $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId());
86: $session->save();
87: $sessionId = $session->getId();
88: $newFilename = 'import_'.$sessionId.'_'.$uploadFile;
89: rename($path.$uploadFile, $path.$newFilename);
90: $session->setFile($newFilename);
91: $session->save();
92: $this->setData(file_get_contents($path.$newFilename));
93: Mage::register('current_dataflow_session_id', $sessionId);
94: }
95: }
96: return $this;
97: }
98:
99: }
100: