00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Varien_Convert_Adapter_Http extends Varien_Convert_Adapter_Abstract
00036 {
00037 public function load()
00038 {
00039 if (!$_FILES) {
00040 ?>
00041 <form method="POST" enctype="multipart/form-data">
00042 File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
00043 </form>
00044 <?php
00045 exit;
00046 }
00047 if (!empty($_FILES['io_file']['tmp_name'])) {
00048 $this->setData(file_get_contents($_FILES['io_file']['tmp_name']));
00049 }
00050 return $this;
00051 }
00052
00053 public function save()
00054 {
00055 if ($this->getVars()) {
00056 foreach ($this->getVars() as $key=>$value) {
00057 header($key.': '.$value);
00058 }
00059 }
00060 echo $this->getData();
00061 return $this;
00062 }
00063
00064
00065 public function loadFile()
00066 {
00067 if (!$_FILES) {
00068 ?>
00069 <form method="POST" enctype="multipart/form-data">
00070 File to upload: <input type="file" name="io_file"/> <input type="submit" value="Upload"/>
00071 </form>
00072 <?php
00073 exit;
00074 }
00075 if (!empty($_FILES['io_file']['tmp_name'])) {
00076
00077 $uploader = new Varien_File_Uploader('io_file');
00078 $uploader->setAllowedExtensions(array('csv','xml'));
00079 $path = Mage::app()->getConfig()->getTempVarDir().'/import/';
00080 $uploader->save($path);
00081 if ($uploadFile = $uploader->getUploadedFileName()) {
00082 $session = Mage::getModel('dataflow/session');
00083 $session->setCreatedDate(date('Y-m-d H:i:s'));
00084 $session->setDirection('import');
00085 $session->setUserId(Mage::getSingleton('admin/session')->getUser()->getId());
00086 $session->save();
00087 $sessionId = $session->getId();
00088 $newFilename = 'import_'.$sessionId.'_'.$uploadFile;
00089 rename($path.$uploadFile, $path.$newFilename);
00090 $session->setFile($newFilename);
00091 $session->save();
00092 $this->setData(file_get_contents($path.$newFilename));
00093 Mage::register('current_dataflow_session_id', $sessionId);
00094 }
00095 }
00096 return $this;
00097 }
00098 }