webservice/application/controllers/ImportController.php
Michael RICOIS 5a72bd68cb 2.4 rev 1821
2013-11-05 11:18:30 +00:00

78 lines
2.2 KiB
PHP

<?php
class ImportController extends Zend_Controller_Action
{
public function fileformAction()
{
$this->_helper->layout()->disableLayout();
$this->view->inlineScript()->appendFile('/scripts/jquery.form.js');
$this->view->inlineScript()->appendFile('/scripts/jqueryprogressbar.js');
$this->view->assign('filesize', ini_get('upload_max_filesize'));
$request = $this->getRequest();
$idClient = $request->getParam('idClient', null);
$login = $request->getParam('login', null);
$this->view->assign('idClient', $idClient);
$this->view->assign('login', $login);
}
public function fileuploadAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$idClient = $request->getParam('idClient');
$login = $request->getParam('login');
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'path');
$path = realpath($config->data).'/validation';
if(!file_exists($path)) mkdir($path);
if ( isset($_FILES) && count($_FILES)==1 ){
$n = $_FILES['fichier']['name'];
$s = $_FILES['fichier']['size'];
$tmp_name = $_FILES['fichier']['tmp_name'];
$extValide = array('csv');
$extension = strrchr($n,'.');
$extension = substr($extension,1);
//Vérifier l'extension du fichier
if(!in_array($extension, $extValide)){
echo "Extension de fichier incorrect !";
} elseif (move_uploaded_file($tmp_name, $path.'/'.$idClient.'-'.$name.'.'.$extension)){
echo "Fichier envoyé, <a href=\"".
$this->view->url(array(
'controller' => 'import',
'action' => 'checkfile',
'file' => $idClient.'-'.$name.'.'.$extension,
))."\">Vérifier le format</a>";
} else {
echo "Erreur : ".$_FILES['fichier']['error'];
}
}
}
/**
* Etat de progression de l'upload du fichier
*/
public function fileprogressAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$key = $request->getParam('key', '');
if (!empty($key)) {
//$rep sera égal à false si la clef n'existe pas dans le cache apc
$rep = apc_fetch('upload_'.$key);
echo json_encode($rep);
}
}
}