Jump to content

[SOLVED] copy() outside script directory


severndigital

Recommended Posts

I would like to work with files that are located outside of the directory my php script is in.

 

when I use the copy() command the script doesn't seem to want to work.

 

am I doing something wrong? or is there a different command I should be using?

 

here is my code

// File services
$filename = "VCADexport.txt";
$filepath = "/home/fedex/fedex_output/";

//$templatename = "VCADexport.txt";
//$templatepath = "/home/fedex/fedex_empty_file/";

$backupname = "VCADexport-$timestamp.txt";
$backuppath = "/home/fedex/fedex_backup/";

//move the original file to the backup area
$filestring = "$filepath$filename";
$backupstring = "$backuppath$backupname";

$makeCopy = copy($filestring,$backupstring);

 

I am pretty sure my permissions are correct. I chmod 777 all the files and directories I needed to use.

 

Any help would be great .. thanks,

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/73517-solved-copy-outside-script-directory/
Share on other sites

yes .. all information is being output correctly from the script .. i echoed each variable before I posted the script.

 

my mistake I forgot to copy and paste that line of code.

 

should be

 

$timestamp = time();

 

thanks,

chris

I got it working.

 

It was a permissions problem on the backup directory.

 

I also changed the copy() command to be included in an If statement something like this

 

if(!copy($filename,$copyname){
echo 'the file was not copied';
}

which helped me with error correction.

 

thanks,

chris

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.