"No such file or directory " error but the file is saved in the database

Asked

Viewed 6,172 times

0

I have the following problem: when I submit a form containing photographs the error described in the title appears. If you only upload a photo, it will no longer appear. But even if you make a mistake, it will save the images in the database. Can anyone tell me the origin of this error? upload code:

UPLOAD IMAGES

if (isset($_POST['enviar'])) {

    // INFO DAS IMAGENS
    $file=$_FILES['img'];
    $numfile=count(array_filter($file['name']));

    //PAsta para onde vão os arquivos
    $folder='fotografias';

    //tipos de ficheiros
    $extensoes= array('image/jpeg', 'image/png', 'image/gif');
    $maxsize=1024*1024*5;

    //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 pelo menos 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[$i]=microtime().".$extensao";

            if($error !=0)
                $msg[]="<b>$name:</b>".$errormsg[$error];
            else if (!in_array($type, $extensoes))
                $msg[]="<b>$name:</b> Erro! Imagem nao suportada!";
            else if ($size>$maxsize)
                $msg[]="<b>$name:</b> Erro! Imagem ultrapassa o limite de 5Mb!";
            else{

                if (move_uploaded_file($tmp, $folder."/".$novonome[$i]))
                    $msg[]="<b>$name:</b> Upload realizado com sucesso";

                else
                    $msg[]="<b>$name:</b> Ocorreu um erro!";

            }  



            }

    }


}


$um=$novonome[0];
$dois=$novonome[1];
$tres=$novonome[2];
$quatro=$novonome[3];
$cinco=$novonome[4];

Insert function

inserir(array("categoria","marca","modelo","ano","horas","img1","img2","img3","img4","img5"), array($categoria,$marca,$modelo,$ano,$horas,$um,$dois,$tres,$quatro,$cinco),"artigos");

Two errors arise:

Error 1

Warning: move_uploaded_file(photographs/0.95092900 1449161528.jpg): failed to open stream: No such file or directory in C: wamp www dtcr admin proc_inserir.php on line 65

Erro2

Warning: move_uploaded_file(): Unable to move 'C: wamp tmp php6409.tmp' to 'fotografias/0.95092900 1449161528.jpg' in C: wamp www dtcr admin proc_inserir.php on line 65

Line 65 is the one containing the following code:

if (move_uploaded_file($tmp, $folder."/".$novonome[$i]))
  • Try using absolute paths in the upload. How C:\fotografias\caminho\do\arquivo.jpg

  • Put a bar / in front of fotografias and say what you have returned.

1 answer

3


Set the full path from where the image will be saved. in your case is saving to 'photographs/xxxxxxxxxxxxx.jpg'

try adding to the folder be: 'c:/.../.../.../photographs/xxxxxxxxxxxxxxxx.jpg'

changing the line

$folder='c:/teste/pasta/fotografias';
  • but I do not know the name of the photo.... I just noticed that it keeps the name in the bank but does not move the photo to the folder!

  • 1

    but you know where the folder is that will be saved. : ) edit the line where $Folder is and put the full path of the FOLDER* :)

  • I’ll try it. but what’s weird is that I’ve been developing it for some time and it was working perfectly

  • Note the error: Unable to move 'C: wamp tmp php6409.tmp' to 'photographs/0.95092900 1449161528.jpg' it filled in the full path to the temporary image, but at the destination address it does not have the full path. Try there and if error occurs just say.

  • 1

    Solved! tried and worked. thought better and in fact I had moved the folder file and had not updated there! Thanks!

Browser other questions tagged

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