How to give file permissions while uploading my code move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);

1 Answer 1


you can give file permission like

$fp = fopen($file, 'w');
    fwrite($fp, $content);
    chmod($file, 0777);  //changed to add the zero

chmod ("/yourdir/yourfile", 0777);

get the reference from here

  • Thanks for comment Rohit but when i download file i am getting error of file Failed - Server problem like ths. and for download i have used code like this <a href='.$_SERVER["DOCUMENT_ROOT"]."/demo/uploads/".$row["invoicefile"].' download>Download</a> Nov 15, 2018 at 9:45
  • File permission server its 777 only Rohit Nov 15, 2018 at 9:55
  • double check file is exist at $_SERVER["DOCUMENT_ROOT"]."/demo/uploads/".$row["invoicefile"] or not? and maybe you have not enough permission to demo or uploads folder, just try directly in url to open your file
    – Rohit
    Nov 16, 2018 at 4:45
  • Thanks for reply Rohit i got this error when i directly open by url error Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Nov 16, 2018 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.