Small syntax error ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Small syntax error ?

Post by MiniMonty »

Hi all,

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 ) ;
}
All and any help much appreciated.
Best wishes
Monty
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Small syntax error ?

Post by AbraCadaver »

Code: Select all

echo $course_name;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Small syntax error ?

Post by MiniMonty »

AbraCadaver wrote:

Code: Select all

echo $course_name;
Prints the course name to the browser exactly as it's been declared.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Small syntax error ?

Post by mikosiko »

maybe you already checked it... but...

did you check the folder/files permits under "the_courses" , "members" and "members/<$id>" ($id=1 in your error code) ?
Post Reply