PHP Uploads - Sorry!!!
| From: | Corin Rathbone | Date: | Mon, 23 Jul 2001 17:38:57 +0000 |
| Subject: | PHP Uploads - Sorry!!! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-59248@lists.php.net to get a copy of this message | ||
Sorry to again bring up the subject, but could somebody please help me with
file uploads. I have written the script below, but it doesn't work properly.
please help. Alternatively, could somebody give me a simple upload script.
My system is Win 98, Apache 1.3.17, php 4.0.5, IE5. The code is below.
Thanks,
Corin Rathbone
<?php
$root_path = "E:/System/htdocs";
if(isset($uploads_go)){
static $worked = array();
for($x=0; $x<9; $x++){
$current_file = $userfile[$x];
$current_file_name = $userfile_name[$x];
$current_file_size = $userfile_size[$x];
$current_file_path = $root_path.$path_to_file[$x];
print( "$x<br>\n" );
print( "$current_file<br>\n" );
print( "$current_file_name<br>\n" );
print( "$current_file_size<br>\n" );
print( "$current_file_path<br><br>\n" );
if(!$current_file=""){
if(!file_exists($current_file_path)){
//copy("$current_file", "$current_file_path");
//unlink($current_file);
$fp = fopen("$current_file_path", "wb") or die("Could not write
file!");
fwrite($fp, "$current_file") or die("Could not write file!");
fclose($fp) or die("Could not close file pointer!");
$worked[] = 1;
}
else{
//die("File does not exists!");
}
}
else{
$worked[] = 0;
}
}
}
elseif(!isset($uploads_go)){
$cfg_upload_max_filesize = get_cfg_var("upload_max_filesize");
print( "<form action=\"upload.php\" method=\"post\"
enctype=\"multipart/form-data\">\n" );
print( " <input type=\"hidden\" name=\"MAX_FILE_SIZE\"
value=\"$cfg_upload_max_filesize\">\n" );
print( " <input type=\"hidden\" name=\"uploads_go\"
value=\"1\">\n" );
print( " Upload these files:<br>\n" );
print( " File: <input name=\"userfile[0]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[1]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[2]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[3]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[4]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[5]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[6]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[7]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[8]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " File: <input name=\"userfile[9]\"
type=\"file\"><br>Path: <input type=\"text\"
name=\"path_to_file[]\" size=\"40\"><br><br>\n" );
print( " <input type=\"submit\" value=\"Send files\">\n"
);
print( "</form>" );
}
elseif(isset($worked)){
for($x=0; $x<9; $x++){
if($worked[$x]){
print( "The file upload for file $path_to_file[$x] was successful<br>\n" );
}
else{
print( "The file upload for file $path_to_file[$x] was <b>not</b>
successful<br>\n" );
}
}
}
else{
print( "<div class=\"main-center\">Please select files to be
uploaded</div>" );
}
?>