I'm trying to upload media to my server with a php code. I have refilled the code a few times and I believe there is absolutely nothing wrong with it. I researched the subject and saw that my upload_tmp_dir
folder is set to no value
. Well remember that the same code on the pc works perfectly.
I then tried to set some folder from the command line, but I did not get anything,
I access php.ini and it looks like this:
HowcanIthendefinethetemporaryfilesfolder.BecauseIthinkthiswillputanendtomyproblems.
Ievenusedthefollowingcode:
<?php$field='arquivo';?><formenctype="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="POST">
<input name="<?php echo $field;?>" type="file" />
<input type="submit" value="send" />
</form>
This code says that the file was in the / tmp / folder, but the upload command is not working, not able to upload anything through the php code.
Code that I use to TRY to upload
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="img" />
<input type="text" name="titu" placeholder="Titulo" />
<input class="lal" type="submit" name="cadastrar" value="Cadastrar" >
</form>
<?php
if(isset($_POST['cadastrar'])){
/* IMAGEM */
$img = $_FILES['img'];
$name =$img ['name'];
$tmp =$img ['tmp_name'];
$size =$img ['size'];
$ext =end(explode('.',$name));
$pasta ='imagens';
$maxSize =1024 * 1024;
$permiti =array('jpg', 'jpeg', 'png');
$titu = filter_input(INPUT_POST, 'titu');
if(empty($titu)){
echo "<div style='width:500px; text-align:center;'><font style='font-weight:bold'>Preencha Todos os Campos</font></div";
}else{
$variavel = $titu;
//Conversao Concluida
$urll = strtolower( preg_replace('/[^a-zA-Z0-9-]/', "_",
strtr(utf8_decode(trim($variavel)), utf8_decode("áàãâéêíóôõúüñçÁÀÃÂÉÊÍÓÔÕÚÜÑÇ")
,"aaaaeeiooouuncAAAAEEIOOOUUNC")) );
//Exibindo a variavel limpa, sem nenhum espaço ou caracter especial
echo $urll;
$name = uniqid().'.'.$ext;
try{
$stmte = $pdo->prepare("INSERT INTO post(TITULO, IMAGEM, URL) VALUES (:1, :2, :3)");
$stmte->bindParam(":1", $titu , PDO::PARAM_STR);
$stmte->bindParam(":2", $name , PDO::PARAM_STR);
$stmte->bindParam(":3", $urll , PDO::PARAM_STR);
$executa = $stmte->execute();
if($executa){
echo 'Dados inseridos com Sucesso';
$upload = move_uploaded_file($tmp, $pasta.'/'.$name);
}
else{
echo 'Erro ao inserir os dados';
}
}
catch(PDOException $e){
echo $e->getMessage();
}}}
?>