Jump to content

Can't copy file

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
:D

Well I have a problem that me and Örjan together can't solve..


    function process_copy(){

        

        $location = $_REQUEST['new_location'];

        $files = $_REQUEST['new_files'];

        

        $exp = explode("\n", $files);

                

        for($i=0;$i<=count($exp)-2;$i++){

            

            $true = copy($exp[$i], $location);

            

        }

        

        if($true == true){

            

            display_message("success", "<p>File(s) successfully copied to destination folder. <a href='index.php'>Main page</a>.</p>");

            

        }elseif($true == false){

            

            display_message("error", "<p>File(s) were not copied to destination folder. <a href='javascript:history.go(-1);'>Go back</a>.</p>");

            

        }

        

    }


Says:

Quote

Warning: copy(/home/something/public_html/changelog.txt ) [function.copy]: failed to open stream: No such file or directory in /home/something/public_html/demo/fm/includes/fm_class.php on line 677

But this file exists there..


    function process_copy(){

        

        $location = $_REQUEST['new_location'];

        $files = $_REQUEST['new_files'];

        

        $exp = explode("\n", $files);

                

        for($i=0;$i<=count($exp)-2;$i++){

            

            $content = file_get_contents($exp[$i]);

            $open = fopen($location.DIRECTORY_SEPARATOR.basename($exp[$i]), "a");

            $true = fwrite($open, $content);

            fclose($open);

            

        }

        

        if($true == true){

            

            display_message("success", "<p>File(s) successfully copied to destination folder. <a href='index.php'>Main page</a>.</p>");

            

        }elseif($true == false){

            

            display_message("error", "<p>File(s) were not copied to destination folder. <a href='javascript:history.go(-1);'>Go back</a>.</p>");

            

        }

        

    }


Quote

Warning: file_get_contents(/home/something/public_html/changelog.txt ) [function.file-get-contents]: failed to open stream: No such file or directory in /home/something/public_html/demo/fm/includes/fm_class.php on line 672

Hmm.. But this file is there -.-

Posted Image

It is really important, please help me :(

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Errr... does it have permission to access the file?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Well.. I'm trying it in windows and it don't work and in unix apache also :/

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
I think you have a space after the file name, try trimming it.

PHP: trim - Manual

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Wow, it works! :D thank you mate!!

#6
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
No problem! Happened to me once and it really got me frustrated lol

#7
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Okay, another problem :D

                for($i=0;$i<=count($exp)-2;$i++){
                
                    if(!file_exists($location.DIRECTORY_SEPARATOR.basename(trim($exp[$i])))){                
                    
                        $true = rename(trim($exp[$i]), $location.DIRECTORY_SEPARATOR.basename(trim($exp[$i])));
                    
                    }
            
                }
        
                if($true == true){
            
                    display_message("success", "<p>File(s) successfully moved to destination folder. <a href='index.php'>Main page</a>.</p>");
            
                }elseif($true == false){
            
                    display_message("error", "<p>File(s) were not moved to destination folder. <a href='javascript:history.go(-1);'>Go back</a>.</p>");
            
                }

Quote

Warning: rename(D:\Program Files\...\htdocs\sms.php,D:\Program Files\...\htdocs\test\copy\sms.php) [function.rename]: No such file or directory in D:\Program Files\...\htdocs\fm2\includes\fm_class.php on line 854

But this folder really does exists (this test/copy) hmm..

#8
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
The code looks fine, I have not ran it yet but it looks pretty simple... do both of those files exist? If you tested it a few times you might of renamed it without realizing lol

#9
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Well.. I didn't change anything and now it works, WTF!