Reputation: 138
I want to upload a file from a form. It's working fine with .doc files but .pdf's don't work all the time. I'm not able to load my pdf named compositionFinale.pdf (3.67 MB)
I tried with another big pdf that was more than my $_FILES["size"]
and I have an error that tells me:"Ce fichier est trop volumineux" (the file is too big).
But with compositionFinale.pdf that is also too big it doesn't pass in my
if ($_FILES["offre"]["size"] > 500000)
(I put a echo to test). I don't have an error at the end and it tells me that the file is uploaded, but when I check in the file it is not.
EDIT: I tried to save this pdf as a reduced size pdf and when I upload my file it tells me that my file is too big. Which is fine. But why does not tell me it is too big when it was not reduced in size? Is anyone see something I don't?
My controller
function publierOffreEmploi()
{
// validation
$this->form_validation->set_rules('poste', 'Poste', 'required|max_length[255]');
$this->form_validation->set_rules('ville', 'Ville', 'required|max_length[50]');
$this->form_validation->set_rules('description', 'Description', 'required');
$this->form_validation->set_rules('secteurs[]', "Secteur(s) d'activité", 'required');
$this->form_validation->set_rules('date_fin_publication', 'Date de la fin de publication', 'required');
$this->form_validation->set_error_delimiters('<br /><span class="error erreur">', '</span>');
// si erreur dans la validation
if ($this->form_validation->run() == FALSE)
{
$this->_layoutHaut();
$this->load->view('entreprise/formulaire_publier_offre_emploi_view');
$this->_layoutBas();
}
// si aucune erreur dans la validation
else
{
// +++++++++++++++++++++++++++++++++++++++++++
$target_dir = "assets/uploads/";
$name = basename($_FILES["offre"]["name"]);
$target_file = $target_dir . basename($_FILES["offre"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$message = '';
// Si le formulaire a bien été envoyé
if(isset($_POST["submit"]))
{
// Vérifie si un fichier est bien sélectionné
if(($_FILES['offre']['name'])!= '')
{
$uploadOk = 1;
$pasDeFichier = "";
}
else
{
// définir le message d'erreur de l'image si le fichier choisi n'est pas une image
$uploadOk = 0;
$pasDeFichier = "Vous devez importer un fichier";
}
// si le fichier existe déja
if (file_exists($target_file))
{
// définir le message d'erreur de l'image si l'image existe déja dans le fichier de téléchargement
$uploadOk = 0;
$message.= "Ce fichier exite déja. Veillez le renommer<br>";
}
// si le fichier est plus gros que 500Ko
if ($_FILES["offre"]["size"] > 500000)
{
echo "too big";
die();
$uploadOk = 0;
// définir le message d'erreur si l'image est trop volumineuse
$message.= "Ce fichier est trop volumineux<br>";
}
// définir les formats autorisés
if($imageFileType != "pdf" && $imageFileType != "doc" && $imageFileType != "docx" && $imageFileType != "DOC" && $imageFileType != "DOCX" && $imageFileType != "PDF")
{
// définir le message d'erreur si l'image n'est pas d'un format accepté
$uploadOk = 0;
$message.= "Seuls les fichiers .pdf, .doc et .docx sont acceptés";
}
// si erreur donc pas d'upload et retour au formulaire avec message d'erreur en fonction de l'erreur
if ($uploadOk == 0)
{
if ($pasDeFichier != "") {
$data=array();
$data["message"]= $pasDeFichier;
$this->_layoutHaut();
$this->load->view('entreprise/formulaire_publier_offre_emploi_view', $data);
$this->_layoutBas();
}
else{
$data=array();
$data["message"]= $message;
$this->_layoutHaut();
$this->load->view('entreprise/formulaire_publier_offre_emploi_view', $data);
$this->_layoutBas();
}
}
/*si l'image a été uploadé*/
else
{
if (move_uploaded_file($_FILES["offre"]["tmp_name"], $target_file)){
}
// Création d'une variable contenant le id de l'entreprise connectée
$idEntreprise = $this->entreprise_model->lire('id', $conditions = array('courriel' => $_SESSION["courriel_entreprise"]));
/*Transformer l'objet en tableau. Nous permet de stocker le id*/
$data=array();
$data["idEntreprise"]= $idEntreprise;
foreach ($idEntreprise as $id) {
}
// ------------------------------ CHECKBOX SECTEURS -----------------------------------------
// Récupération et concaténation des valeurs du checkbox multiple (secteurs)
//déclaration de la variable qui contiendra tous les secteurs
$secteurs ='';
//boucle afin d'optenir tous les secteurs
for ($i=0;$i<count($_POST['secteurs']);$i++)
{
//concaténation des champs
$secteurs .= $_POST['secteurs'][$i];
}
// données envoyées au modèle
$form_data = array(
'poste' => set_value('poste'),
'ville' => set_value('ville'),
'description' => set_value('description'),
'date_fin_publication' => set_value('date_fin_publication'),
'entreprise_id' => $id['id'],
'secteur' => $secteurs,
'type_offre_id' => 2,
'statut_offre_id' => 2,
'offre' => $name
);
// insertion dans la bd
// si l'insertion est un succes
if ($this->offre_model->inserer($form_data) == TRUE)
{
redirect('offre_controller/succes_publication_offre_emploi');
}
// si l'insertion est un echec
else
{
redirect('offre_controller/echec_publication_offre');
}
}
}
}
}
My pdf file
My form
<!-- UPLOAD DE L'OFFRE (PDF, DOC, DOCX) -->
<p>
<!-- affichage du message (gestion des messages d'erreurs) -->
<label for="offre" class="labelVisible labelFile">Veuillez importer votre offre d'emploi<span class="required"></span></label>
<?php echo form_error('offre'); ?>
<input id="offre" type="file" name="offre"/>
<br />
<?php
// si un mesasge d'erreur existe
if(isset($message))
{
?>
<span class="erreur"> <?php echo $message; ?></span>
<?php
}
?>
</p>
Thanks
Upvotes: 0
Views: 962
Reputation: 8385
I bet that PHP upload_max_filesize
is set as default (2MB) you need to go to php.ini file and search for upload_max_filesize
and change that to whatever you need (8MB, 32MB...). Also you need to set post_max_size
to same size or higher.
I assume you are on Windows machine, running XAMPP, right click on icon and look for php.ini file open it and do your magic.
Upvotes: 1