在OpenShift上使用PHP上载文件

在OpenShift上使用PHP上载文件,php,file-upload,openshift,redhat,Php,File Upload,Openshift,Redhat,我正在尝试使用以下代码上载图像: index.php: 更新2: 我将目标目录从“uploads/”更改为“/uploads/”&它在本地主机上工作,但在托管服务器上不工作。我找到了解决方案。我必须改变: $target_dir = dirname(__FILE__) ."/uploads/"; 到 dirname(uuu FILE_uuu)指文件的完整路径和文件名。您是否在upload\u photo.php附近创建了文件夹uploads?@rajeshnair是的。我将用项目的视图更新我的

我正在尝试使用以下代码上载图像:

index.php: 更新2:
我将目标目录
“uploads/”
更改为
“/uploads/”
&它在本地主机上工作,但在托管服务器上不工作。

我找到了解决方案。我必须改变:

$target_dir = dirname(__FILE__) ."/uploads/";


dirname(uuu FILE_uuu)
指文件的完整路径和文件名。

您是否在upload\u photo.php附近创建了文件夹uploads?@rajeshnair是的。我将用项目的视图更新我的答案。你查看错误日志了吗?@JayBlanchard没有,我不知道怎么做。您能指导我完成这个过程吗?@JDev-您的日志文件应该位于
/var/log/
-如果您使用的是共享软管,请查看
公共html
文件夹之前或中的某个位置,该文件应称为
错误日志
Pride。几年前,我注意到我只有在寻求帮助后才能找到问题的答案。当有可能被另一个男人展现出来时,男性的某些心理因素会让我们的决心和创造力过度膨胀骄傲说不要寻求帮助。。。然后(有时)在提供帮助的过程中提供答案。早点寻求帮助。^)
// This function is included from another .php file
function checkUploadedPhoto() {
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["myphoto"]["name"]);

    if(isset($_FILES['myphoto']) AND $_FILES['myphoto']['error'] == 0) {
        // Check size
        if($_FILES['myphoto']['size'] <= 1000000) {
            // Get extension name
            $fileInfo = pathinfo($_FILES['myphoto']['name']);
            $upload_extension = $fileInfo['extension'];
            $allowed_extensions = array('jpg', 'jpeg', 'gif', 'png');

            // Check if the file already exists
            if (file_exists($target_file)) {
                echo "Sorry, file already exists.";
            }

            // Check if the file has a correct, expected extension
            if(in_array($upload_extension, $allowed_extensions)) {
                if(move_uploaded_file($_FILES['myphoto']['tmp_name'], $target_file)) {
                    return true;
                }
            }
            else
                echo "error3";
        }
        else
            echo "error2";
    }
    else
        echo "error1";

    echo "<pre>". print_r($_FILES) ."</pre>";
    echo "Error code: " .$_FILES['myphoto']['error'] ."<br/>";
    return false;
}

if(checkUploadedPhoto()) {
    header("Location: index.php");
}
else {
    echo "upload error";
}
// This condition is true
if (!is_writeable('uploads/' . $_FILES['myphoto']['name'])) {
    die("Cannot write to destination file");
}
$target_dir = "uploads/";
$target_dir = dirname(__FILE__) ."/uploads/";