I had a script which worked until I added one variable and after a lot of head scratching and experimentation I'm turning
to wiser heads for help !
The function of the script is to copy a file into a directory, download it then delete it.
The file name is a variable.
The error I get is this:
Warning: copy(members/1/) [function.copy]: failed to open stream: Is a directory in /Sites/com/shutterbugclub/www/d2.php on line 49
failed to copy the_courses/
The code I'm using is this:
Code: Select all
// WHICH COURSE ?
if ($course_num =="1"){
$course_name ="DayOneDigital.zip";
} else if ($course_num =="2"){
$course_name ="TuneInToPrograms.zip";
} else if ($course_num =="3"){
$course_name ="ShutterSpeedsForShutterBugs.zip";
} else if ($course_num =="4"){
$course_name ="ComposeYourself.zip";
} else if ($course_num =="5"){
$course_name ="TheModernPortrait.zip";
} else if ($course_num =="6"){
$course_name ="OutwardBound.zip";
}
// COPY THE FILE TO THE MEMBER FOLDER
$file = "the_courses/" .$course_name;
$newfile = "members/" .$id."/". $course_name;
if (!copy($file, $newfile)) {
echo "failed to copy $file\n";
} else {
// START THE DOWNLOAD
$file = "members/" .$id."/". $course_name;
$filename = $course_name;
header("Pragma: public");
header("Cache-control: private");
header("Content-type: application/zip");
header("Content-disposition:attachment; filename=$filename");
$fp = fopen( $file , 'r' ) ;
while( !feof( $fp ) ){
echo fgets( $fp , 4096 ) ;
}
// DELETE THE FILE !
fclose( $fp ) ;
unlink( $file ) ;
}
Best wishes
Monty