开发者

String returned by variable not working like the same string entered manually

开发者 https://www.devze.com 2023-02-21 07:28 出处:网络
I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it t

I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks:

<?php
session_name("MyLogin");
session_start();

$targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}

echo $targetFolder;

?>

I added echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter $targetFolder = '/songs/nick'; all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the开发者_开发百科 manually entered string.

Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago!

Thanks,

Nick


Hy

Try use 'songs/' , without the first '/'

0

精彩评论

暂无评论...
验证码 换一张
取 消