0

I checked at least 10 answers, tried with DIR with constant, with basename etc... Same script is working like a charm in other file, but not in this one...

$target = __DIR__ . "/img/blog/" . $_FILES['slika']['name'];
            //proveri da li postoji file za upload
            if (move_uploaded_file($_FILES['slika']['tmp_name'], $target)) {
                if (isset($_POST['published'])) {
                    $blog->_db->insert('ets_blog', array(
                        'kategorija' => $_POST['kategorija'],
                        'naslov' => $_POST['naslov'],
                        'tekst' => $_POST['text'],
                        'image' => $_FILES['slika']['name'],
                        'published' => 1
                    ));

Anyway, when i move this IF before (move_uploaded_file) everything is working like a charm except it doesnt create a file, but it stores his name in database... when i echo target folder it's totaly okay. Any suggestions?

cile1993
  • 156
  • 10
  • Have you checked the error logs? – Jay Blanchard Dec 18 '19 at 02:33
  • @JayBlanchard it says something like no such file or directory dunno for target folder, when there clearly is everythink okay... what can cause this other than not having it? Jus to be clear i echoed that $target and it looks like it should... says that with copy instead of move: copy(C:\path\phpB47B.tmp): failed to open stream: No such file or directory in C:\path\create_post.php on line 33 that's the line where move is – cile1993 Dec 18 '19 at 02:56
  • 1
    Does this answer your question? [PHP: move\_uploaded\_file() failed to open stream: No such file or directory](https://stackoverflow.com/questions/10951334/php-move-uploaded-file-failed-to-open-stream-no-such-file-or-directory) – Triby Dec 18 '19 at 04:40
  • Nope already tried all that... just didnt define a constant but used same code in $target = realpath(dirname(__FILE__))) . "/img/blog/" . $_FILES['slika']['name']; – cile1993 Dec 18 '19 at 19:40

1 Answers1

0

Try to replace your $_FILES['slika']['name']; with this basename( $_FILES['slika']['name'] ); . Beacuse your file name isn't formatted