-3

So I have a upload system whereby there is a simple upload button. The upload works fine and uploads into a directory which is designated for it on the server. However move_uploaded_file does not work. Everytime i upload it does not replace the existing file and simply ignores it.

<?php
$fn = "uploads/firstImage/";
$content = ($_POST['content']);
$fp = fopen($fn,"w") or die ("Error opening file!");
fputs($fp, $content);
fclose($fp) or die ("Error closing file!");
echo "<meta http-equiv=\"refresh\" content=\"0; url=changed.php\"/> \n";
?>

Seperate php file when uploading:

<?php
$target = "uploads/firstImage/";
$target = $target . $_FILES['uploaded']['name'];
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file '$target' has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file" ; }
?>

Any help would be appreciated.

  • 1
    Don't run `stripslashes` on file content. It'll destroy image data and mangle other things. – tadman Mar 02 '17 at 23:22
  • Ok thanks i have now removed that. Any idea as to why the file is not being replaced? – user6299715 Mar 02 '17 at 23:26
  • If you've updated your code and the problem persists, please update the code in your question. With that said, I don't see any code that checks to see that `$_POST['content']` is even meaningful file content. – Mike 'Pomax' Kamermans Mar 02 '17 at 23:35

1 Answers1

2

the php documentation says that move_uploaded_file receives two parameters.

move_uploaded_file ( string $filename , string $destination );

you are missing the destination

  • Done thanks, but still it is not replacing the file? – user6299715 Mar 02 '17 at 23:55
  • do you have write permissions in the target directory? try a chmod -R 777 on the target, very that the target be accessible for php and check this http://stackoverflow.com/questions/18929178/move-uploaded-file-function-is-not-working – Frederick Álvarez Mar 03 '17 at 00:10