Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts

    failed to open stream: Permission denied

    I am getting this error in my code:

    Code:
    Warning: move_uploaded_file(/Goals.doc): failed to open stream: Permission denied in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    
    Warning: move_uploaded_file(): Unable to move '/var/tmp/php1x8LmI' to '/Goals.doc' in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    darnGoals.docIt worked
    I am writing a script to be able to upload files remotely to a server. The site is being hosted at ipowerweb.com ...I figure this is probably a security issue with them? If so, is there a way to log in or something of the sort right before uploading the file?

    This is a test script btw...so I can implement it in my much larger one when I figure out the correct code...

    Any suggestions?

    Thanks!

    Smesh

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    1. Check your chmod for your folder. Systemwide read and write privileges?
    2. Check your phpinfo(). Is safe mode disabled? If not, your going to need another method to do this, as core php won't allow it.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts
    how do you check the chomd for the folder?

    THanks!
    SMesh

  • #4
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ok...so I changed the chomd of the folder to everything...and I checked the phpinfo();

    Under Configure Command safe mode is enabled
    and under the PHP Core Configureation it says that safe_mode is Off

    Is this good or bad?

    If it's bad...how can I get around all this to have people upload files to the server from a php forum/script?

    Thanks!

    Smesh

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by smeshy123
    Under Configure Command safe mode is enabled
    and under the PHP Core Configureation it says that safe_mode is Off
    I don't understand what you mean, is safe mode on or off?
    If either safe_mode is on or file_uploads are off, you cannot use move_uploaded_file.
    Yes, there are ways to get around this, though they may not produce exactly what you want. I'm by no means a filesystem wizard, so I'm not certain what functions can and cannot be used with safe_mode enabled. As well, what version of php are you using?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Sep 2005
    Location
    Romania
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by smeshy123
    I am getting this error in my code:

    Code:
    Warning: move_uploaded_file(/Goals.doc): failed to open stream: Permission denied in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    
    Warning: move_uploaded_file(): Unable to move '/var/tmp/php1x8LmI' to '/Goals.doc' in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    darnGoals.docIt worked
    I am writing a script to be able to upload files remotely to a server. The site is being hosted at ipowerweb.com ...I figure this is probably a security issue with them? If so, is there a way to log in or something of the sort right before uploading the file?

    This is a test script btw...so I can implement it in my much larger one when I figure out the correct code...

    Any suggestions?

    Thanks!

    Smesh
    as far as i see you are trying to upload files to root directory "/" and that's why permision denied.
    try to move the vile to something like /home/voxroxor/public_html/Testing/Test/Upload./
    and set that dir to 777
    can we have a look at test.php , line 14 ?

  • #7
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    $thisfile = $_SERVER['PHP_SELF'];
    $message = '
    <form enctype="multipart/form-data" method="post" action="'.$thisfile.'">
    <input type="file" name="file" />
    <br />
    <input type="submit" name="submit" value="submit" />
    ';
    if (!isset($_POST['submit'])) {
        echo $message;
    } elseif ($_POST['submit'] == 'submit') {
        $uploaddir = 'http://host363.ipowerweb.com/~voxroxor/Testing/Test/';
        $uploadfile = $uploaddir . basename($_FILES['file']['name']);
        if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
            echo "It worked";
        } else {
            echo "darn";
        }
        $file = $_FILES['file']['name'];
        echo $file;
        $message = 'It worked';
        echo $message;
    } else {
        $message = 'Damn it';
        echo $message;
    }
    Line 14:
    Code:
        if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
    Changed the permissions of the folder already, and changed the dir upload to an absolute path. Same error but looks a little different now...shown below:
    Code:
    arning: move_uploaded_file(http://host363.ipowerweb.com/~voxroxor/Testing/Test/test): failed to open stream: HTTP wrapper does not support writeable connections. in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    
    Warning: move_uploaded_file(): Unable to move '/var/tmp/phpW3Pe9K' to 'http://host363.ipowerweb.com/~voxroxor/Testing/Test/test' in /home/voxroxor/public_html/Testing/Test/test.php on line 14
    Any other way of doing this? I think I may have found one using ftp connections and uploading via ftp...but if there is an easier way out there...that would be great.

    Any Idea's?

    Thanks!

    Smesh

  • #8
    New Coder
    Join Date
    Sep 2005
    Location
    Romania
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    change:
    PHP Code:
     $uploaddir 'http://host363.ipowerweb.com/~voxroxor/Testing/Test/'
    to:
    PHP Code:
    $uploaddir '/home/voxroxor/public_html/Testing/Test/'
    see my reviews here

  • #9
    New Coder
    Join Date
    Nov 2004
    Posts
    91
    Thanks
    1
    Thanked 0 Times in 0 Posts
    IT WORKED!!!

    Thank you sooooo much!

    Can anyone explain to me why that path works while the other one doesn't? Or why just '/' doesn't work?

    Thanks!

    Smesh

  • #10
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When you use PHP's filesystem functions (or at least, use ones that are going to be modifying the filesystem in some way) then you need to use the actual path on the server, not the URL. Some filesystem functions (like fopen(), fread() etc.) can be used on remote files and the filename can begin with http:// or another URL wrapper. When it comes to moving a file on your server, you must use a server path and not a URL wrapper. (eg: /home/username/public_html or whatever your root directory is)

    Edit:
    Oh, and just a / doesnt work becuase the actual root of your files on the server is not the same as the / root on the web. On most hosting setups, you cannot upload to the main root directory (/), but only the directory where your actual website contents are held (/home/user/public_html).

    If you think about it as when you go to www.yourwebsite.com, you are seeing the contents of /home/yourwebsite/public_html

  • #11
    New to the CF scene
    Join Date
    Jan 2008
    Location
    Faisalabad - Pakistan
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    failed to open stream: HTTP wrapper does not support writeable connections.


    I m facing this problem too but i solved it using CHMOD permissions

  • #12
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can you help me

    Warning: move_uploaded_file(../images/Image/product/480e5a9f_812.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/apple8/domains/apple8.vn/public_html/includes/function_admin.php on line 440

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phprtGs9z' to '../images/Image/product/480e5a9f_812.jpg' in /home/apple8/domains/apple8.vn/public_html/includes/function_admin.php on line 440



    code:
    PHP Code:
    [QUOTE]
    <?php

    function listCategory($base_url$search ''$level 0$leveltext ''$parent_id 0)
    {
        global 
    $db$template$lang$gArrTableRowClass$gArrVisibleImages;
        
    $sql "SELECT * FROM " PREFIX "category WHERE parent_id=" $parent_id " ORDER BY cat_no";
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }    
        
    $data_rows $db->sql_numrows($result); 
        
        if (
    $data_rows 0) {
            
    $data_set $db->sql_fetchrowset($result);
            
            
    $level ++;
            
            for(
    $i=0$i<$data_rows$i++)    {
                
    $level_text =  (empty($leveltext)) ? ($i 1) : str_repeat("&nbsp;"$level) . $leveltext "." . ($i 1);
                
    $cat_active = ($data_set[$i]['cat_active'] == 0) ? '<img alt="Invisible" src="' $gArrVisibleImages[0] . '" border=0>' '<img alt="Visible" src="' $gArrVisibleImages[1] . '" border=0>';
                if (!empty(
    $search))
                    
    $pos strstr(strtoupper($data_set[$i]['cat_name']), strtoupper($search));
                else
                    
    $pos 1;
                if (
    $pos)
                {
                    
    $categoryHasChild isCategoryHasChild($data_set[$i]['cat_id']);
                    
    $template->assign_block_vars("table_rows", array(
                            
    "INDEX" => $data_set[$i]['cat_id'],
                            
                            
    "NUMBER" => $level_text,
                            
    "TD_CLASS" => $gArrTableRowClass[$i 2],
                            
    "CAT_ID" => $data_set[$i]['cat_id'],
                            
                            
    "CAT_NAME" => $data_set[$i]['cat_name'],
                            
                            
    "CAT_SIGNUP_DATE" => date($lang['long_date'],$data_set[$i]['cat_signupdate']),
                            
    "CAT_VISIBLE" => $cat_active,
                        
                            
    "PERMIT_DEL" => ($categoryHasChild)?'style="display:none"':($data_set[$i]['cat_permit']==1)? 'style="display:none"':'',    
                            
    "PERMIT_SHOW_CHILD" => ($categoryHasChild)?'':'style="display:none"',    
                            
                            
    "LINK_MOVE_UP" => $base_url '&mode=move_up&pcid='.$data_set[$i]['parent_id'].'&id=' $data_set[$i]['cat_id'],
                            
    "LINK_MOVE_DOWN" => $base_url '&mode=move_down&pcid='.$data_set[$i]['parent_id'].'&id=' $data_set[$i]['cat_id'],
                            
    "LINK_EDIT" => $base_url '&mode=edit&id=' $data_set[$i]['cat_id'],
                            ));
                }        
                
    listCategory($base_url$search$level$level_text$data_set[$i]['cat_id']);
            }
            return 
    true;
        }
        return 
    false;
    }

    function 
    listCategoryAccessory($base_url$search ''$level 0$leveltext ''$parent_id 0)
    {
        global 
    $db$template$lang$gArrTableRowClass$gArrVisibleImages;
        
    $sql "SELECT * FROM " PREFIX "category_accessory WHERE parent_id=" $parent_id " ORDER BY cat_no";
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }    
        
    $data_rows $db->sql_numrows($result); 
       
        if (
    $data_rows 0) {
            
    $data_set $db->sql_fetchrowset($result);
            
            
    $level ++;
            
            for(
    $i=0$i<$data_rows$i++)    {
                
    $level_text =  (empty($leveltext)) ? ($i 1) : str_repeat("&nbsp;"$level) . $leveltext "." . ($i 1);
                
    $cat_active = ($data_set[$i]['cat_active'] == 0) ? '<img alt="Invisible" src="' $gArrVisibleImages[0] . '" border=0>' '<img alt="Visible" src="' $gArrVisibleImages[1] . '" border=0>';
                if (!empty(
    $search))
                    
    $pos strstr(strtoupper($data_set[$i]['cat_name']), strtoupper($search));
                else
                    
    $pos 1;
                if (
    $pos)
                {
                    
    $categoryHasChild isCategoryAccessoryHasChild($data_set[$i]['cat_id']);
                    
    $template->assign_block_vars("table_rows", array(
                            
    "INDEX" => $data_set[$i]['cat_id'],
                            
                            
    "NUMBER" => $level_text,
                            
    "TD_CLASS" => $gArrTableRowClass[$i 2],
                            
    "CAT_ID" => $data_set[$i]['cat_id'],
                            
                            
    "CAT_NAME" => $data_set[$i]['cat_name'],
                            
                            
    "CAT_SIGNUP_DATE" => date($lang['long_date'],$data_set[$i]['cat_signupdate']),
                            
    "CAT_VISIBLE" => $cat_active,
                        
                            
    "PERMIT_DEL" => ($categoryHasChild)?'style="display:none"':($data_set[$i]['cat_permit']==1)? 'style="display:none"':'',    
                            
    "PERMIT_SHOW_CHILD" => ($categoryHasChild)?'':'style="display:none"',    
                            
                            
    "LINK_MOVE_UP" => $base_url '&mode=move_up&pcid='.$data_set[$i]['parent_id'].'&id=' $data_set[$i]['cat_id'],
                            
    "LINK_MOVE_DOWN" => $base_url '&mode=move_down&pcid='.$data_set[$i]['parent_id'].'&id=' $data_set[$i]['cat_id'],
                            
    "LINK_EDIT" => $base_url '&mode=edit&id=' $data_set[$i]['cat_id'],
                            ));
                }        
                
    listCategoryAccessory($base_url$search$level$level_text$data_set[$i]['cat_id']);
            }
            return 
    true;
        }
        return 
    false;
    }

    function 
    isCategoryAccessoryHasChild($cat_id)
    {
        global 
    $db;
        
    $sql "SELECT COUNT(cat_id) totalChild FROM " PREFIX "category_accessory WHERE parent_id=" $cat_id;
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }    
        
    $data_rows $db->sql_numrows($result); 
        if (
    $data_rows 0) {
            
    $data_info $db->sql_fetchrow($result);
            if (
    $data_info['totalChild'] == 0)
                return 
    false;
            else
                return 
    true;
        }
        else
            return 
    false;
    }

    function 
    isCategoryHasChild($cat_id)
    {
        global 
    $db;
        
    $sql "SELECT COUNT(cat_id) totalChild FROM " PREFIX "category WHERE parent_id=" $cat_id;
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }    
        
    $data_rows $db->sql_numrows($result); 
        if (
    $data_rows 0) {
            
    $data_info $db->sql_fetchrow($result);
            if (
    $data_info['totalChild'] == 0)
                return 
    false;
            else
                return 
    true;
        }
        else
            return 
    false;
    }





    function 
    thumb($filename$destination$th_width$th_height$forcefill$ImgType)
    {    

       list(
    $width$height) = getimagesize($filename);

        switch (
    $ImgType) {
            case 
    1:
                
    $source imagecreatefromgif($filename);
                break;
            case 
    2:
                
    $source imagecreatefromjpeg($filename);
                break;
            case 
    3:
                
    $source imagecreatefrompng($filename);
                break;
            case 
    6:
                
    $source imagecreatefromwbmp($filename);
                break;
        }
       

       if(
    $width $th_width || $height $th_height){
         
    $a $th_width/$th_height;
         
    $b $width/$height;

         if((
    $a $b)^$forcefill)
         {
             
    $src_rect_width  $a $height;
             
    $src_rect_height $height;
             if(!
    $forcefill)
             {
               
    $src_rect_width $width;
               
    $th_width $th_height/$height*$width;
             }
         }
         else
         {
             
    $src_rect_height $width/$a;
             
    $src_rect_width  $width;
             if(!
    $forcefill)
             {
               
    $src_rect_height $height;
               
    $th_height $th_width/$width*$height;
             }
         }

         
    $src_rect_xoffset = ($width $src_rect_width)/2*intval($forcefill);
         
    $src_rect_yoffset = ($height $src_rect_height)/2*intval($forcefill);

         
    $thumb  imagecreatetruecolor($th_width$th_height);
         
    imagecopyresized($thumb$source00$src_rect_xoffset$src_rect_yoffset$th_width$th_height$src_rect_width$src_rect_height);

         
         switch (
    $ImgType) {
            case 
    1:
                
    imagegif($thumb,$destination);
                break;
            case 
    2:
                
    imagejpeg($thumb,$destination);
                break;
            case 
    3:
                
    imagepng($thumb,$destination);
                break;
            case 
    6:
                
    imagewbmp($thumb,$destination);
                break;
        }
       }
    }

    function 
    checkImageType($FileImage, &$err_flag, &$err_msg)
    {
        if (
    $FileImage['name'] != '')
        {
            if (
    is_uploaded_file($FileImage['tmp_name']) )
            {
                
    $ImageInfo GetImageSize($FileImage['tmp_name']);
                
    $ImgWidth $ImageInfo[0];
                
    $ImgHeight $ImageInfo[1];
                
    $ImgType "";
                
                switch (
    $ImageInfo[2]) {
                    case 
    1:
                        
    $ImgType ".gif";
                        break;
                    case 
    2:
                        
    $ImgType ".jpg";
                        break;
                    case 
    3:
                        
    $ImgType ".png";
                        break;
                    case 
    6:
                        
    $ImgType ".bmp";
                        break;
                }
                
                if (!empty(
    $ImgType))
                {
                }
                else
                {
                    
    $err_flag++;
                    
    $err_msg 'File: "' $FileImage['name'] . '" is invalid type of picture';
                }
            }
        }
    }


    function 
    uploadImageFixSize($FileImage$FileImageOld$pathImage$preFix, &$FileImageUpdated$sizeFix, &$err_flag, &$err_msg)
    {
        
    $FileImageUpdated $FileImageOld;
        if (
    $FileImage['name'] != '')
        {
            if (
    is_uploaded_file($FileImage['tmp_name']) )
            {
                
    $ImageInfo GetImageSize($FileImage['tmp_name']);
                
    $ImgWidth $ImageInfo[0];
                
    $ImgHeight $ImageInfo[1];
                
    $ImgType "";
                
                switch (
    $ImageInfo[2]) {
                    case 
    1:
                        
    $ImgType ".gif";
                        break;
                    case 
    2:
                        
    $ImgType ".jpg";
                        break;
                    case 
    3:
                        
    $ImgType ".png";
                        break;
                    case 
    6:
                        
    $ImgType ".bmp";
                        break;
                }
                
                if (!empty(
    $ImgType))
                {
                    
                    
    // Generate image ID
                    
    $err_loop 0;
                    
    $i 0;
                    do {
                        
    $FileImageUpdated $preFix generateRandomString(32) . $ImgType;
                        if (!
    file_exists($pathImage $FileImageUpdated)) 
                        {
                            break;
                        }
                        
                        if (
    $i 100)
                        {
                            
    $err_loop 1;
                            break;
                        }
                        
    $i++;
                    } while (
    1);
                    
                    if (!
    $err_loop
                    {
                        if (
    move_uploaded_file($FileImage['tmp_name'], $pathImage $FileImageUpdated))
                        {
                            
    thumb($pathImage $FileImageUpdated$pathImage $FileImageUpdated$sizeFix$sizeFixfalse$ImageInfo[2]);
                            if (!empty(
    $FileImageOld))
                            {
                                if (
    file_exists($pathImage $FileImageOld)) 
                                {
                                    @
    unlink ($pathImage $FileImageOld);
                                }
                            }

                        }
                    }
                    else
                    {
                        
    $err_flag++;
                        
    $err_msg 'File: "' $FileImage['name'] . '" can not upload! Contact admin please!';
                    }
                        
                    
                }
                else
                {
                    
    $err_flag++;
                    
    $err_msg 'File: "' $FileImage['name'] . '" is invalid type of picture';
                }
            }
        }
        
    }

    function 
    uploadImageAndThumb($FileImage$FileImageOld$pathImage$pathImageSmall$preFix, &$FileImageUpdated$sizeFix$sizeFixSmall, &$err_flag, &$err_msg)
    {
        
    $FileImageUpdated $FileImageOld;
        if (
    $FileImage['name'] != '')
        {
            if (
    is_uploaded_file($FileImage['tmp_name']) )
            {
                
    $ImageInfo GetImageSize($FileImage['tmp_name']);
                
    $ImgWidth $ImageInfo[0];
                
    $ImgHeight $ImageInfo[1];
                
    $ImgType "";
                
                switch (
    $ImageInfo[2]) {
                    case 
    1:
                        
    $ImgType ".gif";
                        break;
                    case 
    2:
                        
    $ImgType ".jpg";
                        break;
                    case 
    3:
                        
    $ImgType ".png";
                        break;
                    case 
    6:
                        
    $ImgType ".bmp";
                        break;
                }
                
                if (!empty(
    $ImgType))
                {
                    
                    
    // Generate image ID
                    
    $err_loop 0;
                    
    $i 0;
                    do {
                        
    $FileImageUpdated $preFix generateRandomString(32) . $ImgType;
                        if (!
    file_exists($pathImage $FileImageUpdated)) 
                        {
                            break;
                        }
                        
                        if (
    $i 100)
                        {
                            
    $err_loop 1;
                            break;
                        }
                        
    $i++;
                    } while (
    1);
                    
                    if (!
    $err_loop
                    {
                        if (
    move_uploaded_file($FileImage['tmp_name'], $pathImage $FileImageUpdated))
                        {
                            
    thumb($pathImage $FileImageUpdated$pathImageSmall $FileImageUpdated$sizeFix$sizeFixfalse$ImageInfo[2]);
                            if (!empty(
    $FileImageOld))
                            {
                                if (
    file_exists($pathImage $FileImageOld)) 
                                {
                                    @
    unlink ($pathImage $FileImageOld);
                                }
                                
                                if (
    file_exists($pathImageSmall $FileImageOld)) 
                                {
                                    @
    unlink ($pathImageSmall $FileImageOld);
                                }
                            }

                        }
                    }
                    else
                    {
                        
    $err_flag++;
                        
    $err_msg 'File: "' $FileImage['name'] . '" can not upload! Contact admin please!';
                    }
                        
                    
                }
                else
                {
                    
    $err_flag++;
                    
    $err_msg 'File: "' $FileImage['name'] . '" is invalid type of picture';
                }
            }
        }
        
    }

    function 
    uploadFile($File$FileCu$path$preFix, &$FileCapNhat$LimitFileSize, &$err_flag, &$err_msg)
    {
        
        if ( 
    $File['size'] < $LimitFileSize)
        {
            
    $FileCapNhat $FileCu;
            
            if (
    $File['name'] != '')
            {
                if (
    is_uploaded_file($File['tmp_name']) )
                {
                    
    $FileCapNhat $File['name'];
                    
                    if (
    file_exists($path.$FileCapNhat))
                    {    
                        
    $path_parts pathinfo($FileCapNhat);
                        
    $baseName    $path_parts["basename"];
                        
    $extension    $path_parts["extension"];
                        
    $baseName   substr($baseName0strlen($baseName) - strlen($extension) - 1);
                        while (
    is_file($path $baseName "_$preFix" '.' $extension)) $preFix++;
                        
    $FileCapNhat $baseName "_$preFix" '.' $extension;
                    }
                    
                    
                
                    if (
    move_uploaded_file($File['tmp_name'], $path $FileCapNhat))
                    {
                        if (!empty(
    $FileCu))
                        {
                            if (
    is_file($path $FileCu)) 
                            {
                                
    unlink ($path $FileCu);
                                
                            }
                        }

                    }
                }
                else
                {
                    
    $err_flag++;
                    
    $err_msg 'File: "' $File['name'] . '" must has size < ' $LimitFileSize " bytes (=2MB)";
                }
            }
            
        }
        else
        {
            
    $err_flag++;
            
    $err_msg 'File: "' $File['name'] . '" must has size < ' $LimitFileSize " bytes (=2MB)";
        }
    }


    /*Duy define 22-10-2006: xem file New.php de nam ro hon cach goi ham*/




    function getList_CountChild(&$id$table$table_name_as$fieldID$fieldName$table_c$table_c_name_as$total_c_as$total_c_display$sWhere$fieldSort$sort "")
    {
        global 
    $db;
        
        
    $sql "SELECT " $fieldName ", " $table_name_as ."." .$fieldID ", count(" $table_c_name_as "." .$fieldID ") as " $total_c_as " FROM " $table " " $table_name_as " LEFT JOIN " $table_c " " $table_c_name_as ." ON " $table_name_as ."." .$fieldID " = " $table_c_name_as ."." .$fieldID " where 1=1 ";
        
        if (
    $sWhere$sql$sql " and " $sWhere;
        
        
    $sql .= " group by "$table_name_as ."." .$fieldID ;
        
        if (
    $fieldSort$sql$sql " ORDER BY " $fieldSort " " $sort;
        
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }
        
        
    $listcat "";
        
        while( 
    $data_set $db->sql_fetchrow($result) )
        {
            
    $s "";
            
            if ((
    $data_set[$fieldID] == $id) )
            {
                if ((
    $db->sql_numrows($result) == 1) && (empty($id))) $id $data_set[$fieldID];
                
    $s " selected=\"selected\"";
            }
            
            
    $listcat .= "<option value=\"".$data_set[$fieldID]."\"$s>" $data_set[$fieldName] . " &nbsp;&nbsp;(" $data_set[$total_c_as] . " " $total_c_display ") </option>\n";
        }
        
        return(
    $listcat);
    }

    function 
    getList2TableJoinID($ParentTable$ParentFieldID$ParentFieldName$ParentWhere$ParentFieldSort$ParentSort$id$table$fieldID$fieldName$sWhere$fieldSort$sort "")
    {
        global 
    $db;
        
    $sql "SELECT " $ParentFieldName "," $ParentFieldID "," $ParentFieldSort 
                
    " FROM " $ParentTable " WHERE 1=1 " ;
        
        if (
    $ParentWhere$sql$sql .     " and "     $ParentWhere;
        
        if (
    $ParentFieldSort$sql$sql" ORDER BY " $ParentFieldSort " " $ParentSort ;        
        
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }
        
        
    $total_rows $db->sql_numrows($result); 
        
    $ParentData_set $db->sql_fetchrowset($result);
        
    $listcat "";
        
        
    $pos strpos($id"_");
        if (
    $pos 0)
        {
            
    $arr_id explode('_'$id);
            
    $select_parent_id 0;
            
    $select_child_id $arr_id[1];
        }
        else
        {
            
    $select_parent_id $id;
            
    $select_child_id 0;
        }

        
        for(
    $i=0$i<$total_rows$i++)    
        {
            
    $s "";
            if (
    $ParentData_set[$i][$ParentFieldID] == $select_parent_id)
            {
                
    $s " selected=\"selected\"";
            }
                
            
    $listcat .= '<option style="color:blue;" value="'.$ParentData_set[$i][$ParentFieldID].'"' $s'>*** ' $ParentData_set[$i][$ParentFieldName] . " ***</option>\n";
            
    $s "";
            
                
            
    $sql "SELECT " $fieldName "," $fieldID "," $fieldSort 
                
    " FROM " $table " WHERE " $ParentFieldID "=" $ParentData_set[$i][$ParentFieldID] ;
                
            if (
    $sWhere$sql$sql " and " $sWhere;
        
            if (
    $fieldSort$sql$sql " ORDER BY " $fieldSort " " $sort;
        
        
            if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }
            
            while( 
    $data_set $db->sql_fetchrow($result) )
            {
                if (
    $pos 0)
                {
                    
    $s "";
                    if (
    $data_set[$fieldID] == $select_child_id)
                    {
                        
    $s " selected=\"selected\"";
                    }
                }
                
    $listcat .= "<option value=\"".$ParentData_set[$i][$ParentFieldID]."_".$data_set[$fieldID]."\"$s>&nbsp;&nbsp;&nbsp;&nbsp;" $data_set[$fieldName] . "</option>\n";
            }
            
        }
        return(
    $listcat);
    }

    function 
    getList2TableJoinID_CountChild($ParentTable$ParentFieldID$ParentFieldName$ParentWhere$ParentFieldSort$ParentSort$id$table$table_name_as$fieldID$fieldName$table_c$table_c_name_as$total_c_as$total_c_display$sWhere$fieldSort$sort "")
    {
        global 
    $db;
        
    $sql "SELECT " $ParentFieldName "," $ParentFieldID "," $ParentFieldSort 
                
    " FROM " $ParentTable " WHERE 1=1 " ;
        
        if (
    $ParentWhere$sql$sql .     " and "     $ParentWhere;
        
        if (
    $ParentFieldSort$sql$sql" ORDER BY " $ParentFieldSort " " $ParentSort ;        
        
        if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }
        
        
    $total_rows $db->sql_numrows($result); 
        
    $ParentData_set $db->sql_fetchrowset($result);
        
    $listcat "";
        
        
    $pos strpos($id"_");
        if (
    $pos 0)
        {
            
    $arr_id explode('_'$id);
            
    $select_parent_id 0;
            
    $select_child_id $arr_id[1];
        }
        else
        {
            
    $select_parent_id $id;
            
    $select_child_id 0;
        }

        
        
        for(
    $i=0$i<$total_rows$i++)    
        {
            
    $s "";
            if (
    $ParentData_set[$i][$ParentFieldID] == $select_parent_id)
            {
                
    $s " selected=\"selected\"";
            }
                
            
    $listcat .= '<option style="color:blue;" value="'.$ParentData_set[$i][$ParentFieldID].'"' $s'>*** ' $ParentData_set[$i][$ParentFieldName] . " ***</option>\n";
            
    $s "";
            
            
    $sql "SELECT " $fieldName ", " $table_name_as ."." .$fieldID ", count(" $table_c_name_as "." .$fieldID ") as " $total_c_as " FROM " $table " " $table_name_as " LEFT JOIN " $table_c " " $table_c_name_as ." ON " $table_name_as ."." .$fieldID " = " $table_c_name_as ."." .$fieldID " where " $table_name_as ."."$ParentFieldID "=" $ParentData_set[$i][$ParentFieldID] ;
        
            if (
    $sWhere$sql$sql " and " $sWhere;
            
            
    $sql .= " group by "$table_name_as ."." .$fieldID ;
            
            if (
    $fieldSort$sql$sql " ORDER BY " $fieldSort " " $sort;
            
        
            if( !
    $result $db->sql_query($sql) ) {    message_die($lang['exec_SQL_error'], __LINE____FILE__$sql); }
            
            
    //echo $sql;
            //die();
            
            
    while( $data_set $db->sql_fetchrow($result) )
            {
                if (
    $pos 0)
                {
                    
    $s "";
                    if (
    $data_set[$fieldID] == $select_child_id)
                    {
                        
    $s " selected=\"selected\"";
                    }
                }



    ?>
    [/QUOTE]
    Last edited by tomy; 10-28-2009 at 10:03 AM.

  • #13
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some help

    Hey everyone,

    I have read the previous threads and think this is the best way of addressing
    the problem I am having, however I cant seem to get the right path. My site is

    java.cms.livjm.ac.uk/homepage/student/folder1/folder2/resources/

    what would the equivilent directory be if I want to write files to the resources folder?

    Thanks in advance
    Last edited by seanrobbo1; 01-28-2010 at 01:03 AM.

  • #14
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Same problem on Windows Server

    Hi, I have been trying to figure this out. I read this entire post but it is not working for me. I am trying to create a simple PHP Upload page. Below is the code for my HTML Form and my uploader.php and the error message that I am getting when trying to upload. Please help, thank you.

    HTML

    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>

    PHP Code:
    <?php
    $target_path 
    "files/upload/";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 

    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo 
    "The file ".  basename$_FILES['uploadedfile']['name']). 
        
    " has been uploaded";
    } else{
        echo 
    "There was an error uploading the file, please try again!";
    }
    ?>
    ERROR MESSAGE

    Warning: move_uploaded_file(files/upload/Label-1.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\inetpub\vhosts\myhomegranite.com\httpdocs\uploader.php on line 6

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php9C08.tmp' to 'files/upload/Label-1.jpg' in C:\inetpub\vhosts\myhomegranite.com\httpdocs\uploader.php on line 6
    There was an error uploading the file, please try again!

  • #15
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Quote Originally Posted by seanrobbo1 View Post
    Hey everyone,

    I have read the previous threads and think this is the best way of addressing
    the problem I am having, however I cant seem to get the right path. My site is

    java.cms.livjm.ac.uk/homepage/student/folder1/folder2/resources/

    what would the equivilent directory be if I want to write files to the resources folder?

    Thanks in advance
    You need to find out the path to your web root (echo $_SERVER['DOCUMENT_ROOT']) then add on the path you see in the browser so in your case if document root was e.g. "/home/wwww/userx/public_html" then you would use /home/wwww/userx/public_html/homepage/student/folder1/folder2/resources/

    HTH,

    Dai


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •