Hi,
I've been trying today to upload a file using a script from a book I've been
learning from.
The script work's fine, except for whe the naem of the file contains an
apostrophe... e.g. " ' ".
The script is:
<?php
$file_dir = "C:\uploade d";
foreach ($_FILES as $file_name => $file_array) {
print "path: ".$file_arr ay['tmp_name']."<br>\n";
print "name: ".$file_arr ay['name']."<br>\n";
print "type: ".$file_arr ay['type']."<br>\n";
print "size: ".$file_arr ay['size']."<br>\n";
if (is_uploaded_fi le($file_array['tmp_name'])) {
move_uploaded_f ile($file_array['tmp_name'],
"$file_dir/$file_array[name]") or die ("Couldn't copy");
print "File was moved!<br><br>" ;
}
}
?>
The output I get when the apsotrophe is added to the file name is:
"
path: C:\WINDOWS\TEMP \php5D.tmp
name: Robert\'s file.txt
type: text/plain
size: 15
Warning: move_uploaded_f ile(C:\uploaded/Robert\'s file.txt): failed to open
stream: No such file or directory in C:\Program Files\Apache
Group\Apache2\h tdocs\php\Hour 9\listing9.14.p hp on line 21
Warning: move_uploaded_f ile(): Unable to move 'C:\WINDOWS\TEM P\php5D.tmp' to
'C:\Documents and Settings\Robert \My Documents\uploa ded/Robert\'s file.txt'
in C:\Program Files\Apache Group\Apache2\h tdocs\php\Hour 9\listing9.14.p hp
on line 21
Couldn't copy
"
Is the error because of the forward slash or because of the \' in the part
"C:\uploade d/Robert\'s file.txt"
Thanks
Robert
I've been trying today to upload a file using a script from a book I've been
learning from.
The script work's fine, except for whe the naem of the file contains an
apostrophe... e.g. " ' ".
The script is:
<?php
$file_dir = "C:\uploade d";
foreach ($_FILES as $file_name => $file_array) {
print "path: ".$file_arr ay['tmp_name']."<br>\n";
print "name: ".$file_arr ay['name']."<br>\n";
print "type: ".$file_arr ay['type']."<br>\n";
print "size: ".$file_arr ay['size']."<br>\n";
if (is_uploaded_fi le($file_array['tmp_name'])) {
move_uploaded_f ile($file_array['tmp_name'],
"$file_dir/$file_array[name]") or die ("Couldn't copy");
print "File was moved!<br><br>" ;
}
}
?>
The output I get when the apsotrophe is added to the file name is:
"
path: C:\WINDOWS\TEMP \php5D.tmp
name: Robert\'s file.txt
type: text/plain
size: 15
Warning: move_uploaded_f ile(C:\uploaded/Robert\'s file.txt): failed to open
stream: No such file or directory in C:\Program Files\Apache
Group\Apache2\h tdocs\php\Hour 9\listing9.14.p hp on line 21
Warning: move_uploaded_f ile(): Unable to move 'C:\WINDOWS\TEM P\php5D.tmp' to
'C:\Documents and Settings\Robert \My Documents\uploa ded/Robert\'s file.txt'
in C:\Program Files\Apache Group\Apache2\h tdocs\php\Hour 9\listing9.14.p hp
on line 21
Couldn't copy
"
Is the error because of the forward slash or because of the \' in the part
"C:\uploade d/Robert\'s file.txt"
Thanks
Robert
Comment