简体   繁体   English

将文件上传到Web根目录之外

[英]Upload file outside web root directory

i want to upload images outside web root directory, but i don't know how to do it. 我想将图像上传到Web根目录之外,但是我不知道该怎么做。
For example i want to put images in var/media3/ , i set the media directory to permissions 777, now i need to modify the code to put images because that can not work. 例如,我想将图像放在var / media3 /中 ,我将媒体目录设置为权限777,现在我需要修改代码以放置图像,因为这不起作用。
I tryed even using $_SERVER['DOCUMENT_ROOT'] but it doesn't work (and honestly I have never tried this kind of thing). 我什至尝试使用$_SERVER['DOCUMENT_ROOT']但是它不起作用(老实说,我从未尝试过这种事情)。

This is the upload.php script: 这是upload.php脚本:

<?php

// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif');

if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){

    $extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);

    if(!in_array(strtolower($extension), $allowed)){
        echo '{"status":"error"}';
        exit;
    }

    if(move_uploaded_file($_FILES['upl']['tmp_name'], 'var/media3/'.$_FILES['upl']['name'])){ // <--The problem is in this string, it won't work
        echo '{"status":"success"}';
        exit;
    }
}

echo '{"status":"error"}';
exit;



Thanks XD 谢谢XD

添加一个斜杠/var/media

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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