简体   繁体   中英

move_uploaded_file is failing

I keep getting this error when trying to move an uploaded file to a directory on my server.

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phposlycV' to '/home/star/mywebsite.org/view/PDFs/Elections/65.PDF'

Here is my code.

if ($_FILES['ufile']['type'] == "application/pdf") {
    $db->exec("INSERT INTO `my_candidates` (`Type`, `ElecName`, `ExpDate`, `FirstName`, `LastName`, `State`, `Bio`) VALUES ('$Type', '$ElecName', '$ExpDate', '$FirstName', '$LastName', '$State', '$Bio')");
    $sql2 = "SELECT max( ID ) AS `ID` FROM `my_candidates` WHERE `Type` = '$Type' AND `ElecName` = '$ElecName' AND `FirstName` = '$FirstName' AND `LastName` = '$LastName'";
    $newFileNameID = implode(' ', $db->query($sql2));
    $new_file_name=$newFileNameID.$Ext;
    rename($_FILES['ufile']["tmp_name"], $new_file_name);
    $tempDir = $_SERVER['DOCUMENT_ROOT'] . "/PDFs/Elections/";
    if (move_uploaded_file($_FILES['ufile']['tmp_name'], $tempDir . $new_file_name)) {
        echo "Uploaded";
} else {
    echo "Not Uploaded";
}

My chmod for that directory is 720. I have been knocking my head against this for hours. Any pointers you guys could throw my way would be much appreciated. The funny thing though it does upload to my $_SERVER[DOCUMENT_ROOT] directory with the error still.

chmod 720 will give read, write and execute permissions to the owner, write permission to the group and no permission at all for other.

If apache is not the owner of the directory, this is probably why it is not working.

Who is the current owner of the directory ? Did you try changing it with chown ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM