extranet/includes/saisie/saisie_logo_upload.php
2010-07-02 13:35:31 +00:00

64 lines
2.0 KiB
PHP

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$output = '<div style="text-align:center;">';
if ( !empty($siren) && isset($_FILES['file']) &&
$_FILES['file']['error']!=UPLOAD_ERR_NO_FILE ) {
$logoFile = $_FILES['file'];
$tmp_file = $logoFile['tmp_name'];
if ( $logoFile['error']!=UPLOAD_ERR_OK ) {
$output.= '';
} elseif ( !is_uploaded_file($tmp_file) ){
$output.= '';
} else {
// On vérifie maintenant l'extension
$extAuthorized = array('jpeg', 'jpg', 'png', 'gif', 'bmp');
$type_file = str_replace('image/', '',$logoFile['type']);
$ext = '';
if ( in_array($type_file, $extAuthorized) ){
$ext = $type_file;
}
if ( !empty($ext) ){
// on copie le fichier dans le dossier de destination
$name_file = $siren.'.'.$ext;
if ( file_exists(PATH_LOGOS . $name_file) ){
unlink(PATH_LOGOS . $name_file);
}
if( !move_uploaded_file($tmp_file, PATH_LOGOS . $name_file) ) {
$output.= '';
} else {
$output.= '<img src="logos/'.$name_file.'&uid='.time().'" />';
$output.= '<br/>';
$output.= '<a id="logo_crop" href="/?page=saisieajax&q=logo/crop/'.
$name_file.'">Editer l\'image</a>';
}
} else {
$output.= '';
}
}
$output.= '</div>';
echo $output;
}
exit;
}
?>
<form id="uploadForm" name="uploadForm" action="/?page=saisieajax&q=logo/upload" method="post" enctype="multipart/form-data">
<input name="MAX_FILE_SIZE" value="100000" type="hidden">
<input type="hidden" name="siren" value="<?=$siren?>"/>
<label>Fichier:</label><input name="file" type="file">
<input value="Envoyer" type="submit">
</form>
<div id="uploadOutput"></div>
<script type="text/javascript">
$('#uploadForm').ajaxForm({
dataType: 'html',
target: '#uploadOutput',
beforeSubmit: function(a,f,o) {
$('#uploadOutput').html('Envoi en cours...');
},
success: function(data) {
$('#uploadOutput').html(data);
return false;
}
});
</script>