Problem with image upload: Warning: move_uploaded_file():

Asked

Viewed 827 times

1

My code is showing an error that never appeared before, when I test on localhost (I use xampp) the images are successfully inserted on the site, but when I do with the hosted site it appears the following error:

Warning: move_uploaded_file(uploads/1193699972.jpg): failed to open stream: No such file or directory in /home/u755489537/public_html/upload/upload.php on line 73

Warning: move_uploaded_file(): Unable to move '/tmp/phpXzwvDc' to 'uploads/1193699972.jpg' in /home/u755489537/public_html/upload/upload.php on line 73

It always worked, but now it started to get wrong, and I didn’t touch any lines of my code, it just started to get wrong. My hosting server is Hostinger, will the problem be the server?

My code is:

<?php
	require_once("../connect.php");	
?>

<?php
	if(!isset($_SESSION["email_profissional"]) || !isset($_SESSION["senha_profissional"])){
		header("Location:logout.php");
		exit;
	}else{
		
	}
	if(is_numeric($_GET['sessao'])){		
	}else{
		header("location:logout.php");
	}
		
	if($_GET['sessao'] == null){
		header("location:logout.php");
	}

	if($_GET['sessao'] != preg_replace("/[^0-9]/", "",$_SESSION['protecao'])){
		header("location:logout.php");
	}else{
		$sessao = $_GET['sessao'];
	}
?>

<?php
if(isset($_POST['upload'])){
		
		//INFORMAÇÃO DAS IMAGEM
		$file = $_FILES['img'];
		$profissional = $_POST['profissional'];
		$numFile = count(array_filter($file['name']));
		
		//PASTA
		$folder = '../upload/uploads';
		
		//REQUISITOS QUE A IMAGEM DEVE OBEDESCER
		$permite = array('image/jpeg', 'image/png');
		$maxSize = 1024 * 1024 * 20;

		//MENSAGENS
		$msg = array();
		$errorMsg = array(
			1 => 'O arquivo enviado excede o limite definido na diretiva upload_max_filesize do php.ini.',
			2 => 'O arquivo excede o limite definido em MAX_FILE_SIZE no formulário HTML.',
			3 => 'O upload do arquivo foi feito parcialmente.',
			4 => 'Nenhum arquivo foi enviado.',
			);
		
		if($numFile <= 0)
			echo 'Selecione uma imagem';
		else{
			for($i = 0; $i < $numFile; $i++){
				$name = $file['name'][$i];
				$type = $file['type'][$i];
				$size = $file['size'][$i];
				$error = $file ['error'][$i];
				$tmp = $file['tmp_name'][$i];
				
				
				$extensao = @end(explode('.', $name));
				$novoNome = rand().".$extensao";
				
				if($error != 0)
					echo "<b style='font-family:arial; color:red;'>$name :</b><p style='font-family:arial; color:red;'> ".$errorMsg[$error]."</p>";
				else if(!in_array($type, $permite))
					echo "<b style='font-family:arial; color:red;'>$name :</b> <p style='font-family:arial; color:red;'> Erro! Imagem não suportada. Use apenas imagens JPG ou PNG</p>";
				else if($size > $maxSize)
					echo "<b style='font-family:arial; color:red;'>$name :</b> <p  style='font-family:arial; color:red;'>Erro! Imagem ultrapassa o limite de 20MB.</p>";
				else{
					if(move_uploaded_file($tmp, $folder.'/'.$novoNome)){
						$sql = "INSERT INTO arquivo (id_arquivo, nome_arquivo, profissional) VALUES (null, '$novoNome', '$profissional')";
						//conexão com o banco de dados
						$con = mysqli_connect($host, $user, $pass) or die ("Configuração de Banco de Dados Errada!");
						//Selecionando o banco de dados...
						mysqli_select_db($con, $db) or die ("Banco de Dados Inexistente!");
						//Inserindo os dados
						mysqli_query($con, $sql) or die ("<font style=Arial color=red><h1>Houve um erro na gravação dos dados</h1></font>");
						echo "<font style=Arial color=green><b>".$name.": Cadastro efetuado com sucesso! O arquivo foi renomeado para ".$novoNome."</b></font><br>";						
					}else{
						echo "<font style=Arial color=red font-weight=bold><b>".$name.": Falha!</b></font><br>";
					}				
				}
			}	
		}	
	}

  • The briefcase uploads exists?

  • 1

    Sorry, it was a stupid mistake of mine, I deleted the uploads folder and had not noticed. Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.