anatak Posted September 4, 2009 Share Posted September 4, 2009 Hello, I have a class to upload pictures. everything works fine except that when the file is saved the first letter (a capital) becomes a small letter. the folder created to contain the image files has the capital. for example the folder created is Ducati_10 the image name in the database is Ducati_10_0.jpeg (Ducati_10 first picture) but the image file written to the Ducati_10 folder is ducati_10_0.jpeg Does anybody know how to preserve the capital when writing a file. I am working on a LAMP Ubuntu system. kind regards anatak Quote Link to comment Share on other sites More sharing options...
RussellReal Posted September 4, 2009 Share Posted September 4, 2009 show some code.. that isn't normal behavior Quote Link to comment Share on other sites More sharing options...
anatak Posted September 4, 2009 Author Share Posted September 4, 2009 possible problem here after reading the code again I think this is the offending line $extension = strtolower(strrchr($file_name,".")); I think it only makes everything after the . in the file name lower characters but maybe it puts every thing in lower chars ? this is in the Upload_Files class some code the name of the folder is send from a form $_POST['bike_folder'] Here I check if the folder exist and mkdir it if it does not exist (sorry comments are sometimes in dutch $log_folder is same as $folder (I still have to clean up the code after it works) $folder='../public_html/picture/'.$_POST['bike_folder'].'/'; $log_folder=$folder; echo '<br />folder: '.$folder; echo '<br />log folder: '.$log_folder; if(!file_exists($folder)){ //folder bestaat niet if(!mkdir($folder)){ //folder bestaat niet en kan niet aangemaakt worden $error=0; }else{ //folder bestaat al $error=5; } } echo 'error code for folder mkdir: '.$error; the class of Upload_Files is below the code $filename= $_POST['bike_folder']."_".$_POST['picture_nr'.$i]; is where I decide the file name every picture has a number at the end for example in folder Ducati_13 are the following pictures Ducati_13_0.jpeg Ducati_13_1.jpeg Ducati_13_2.jpeg except that in my folder the name of the file is ducati_13_0.jpeg ducati_13_1.jpeg ducati_13_2.jpeg $upload_content_pic = new Upload_Files; $upload_content_pic->temp_file_name = trim($_FILES['upload'.$i]['tmp_name']); //$upload_content_pic->file_name = trim(strtolower($_FILES['upload']['name'])); $upload_content_pic->file_name = $_POST['bike_folder']."_".$_POST['picture_nr'.$i].$extension=strtolower(strrchr($_FILES['upload'.$i]['name'],".")); $upload_content_pic->upload_dir = $folder; $upload_content_pic->upload_log_dir = $folder; $upload_content_pic->max_file_size = 200000; $upload_content_pic->banned_array = array(""); $upload_content_pic->ext_array = array(".jpeg",".jpg",".gif"); $path = $upload_content_pic->get_upload_directory(); $filename= $_POST['bike_folder']."_".$_POST['picture_nr'.$i]; $path_to_picture = $path.$filename.$extension; $valid_ext = $upload_content_pic->validate_extension(); $valid_size = $upload_content_pic->validate_size(); $valid_user = $upload_content_pic->validate_user(); $max_size = $upload_content_pic->get_max_size(); $file_size = $upload_content_pic->get_file_size(); $file_exists = $upload_content_pic->existing_file(); Here is the class class Upload_Files { var $temp_file_name; var $file_name; var $upload_dir; var $upload_log_dir; var $max_file_size; var $banned_array; var $ext_array; function print_extension(){ $ext_array = $this->ext_array; foreach($ext_array as $value){ echo $value." "; } } function validate_extension() { //SECTION #1 $file_name = trim($this->file_name); $extension = strtolower(strrchr($file_name,".")); $ext_array = $this->ext_array; $ext_count = count($ext_array); //SECTION #2 if(!isset($file_name)){ return false; }else{ if(!$ext_array){ return true; }else{ foreach($ext_array as $value){ $first_char = substr($value,0,1); if($first_char <> "."){ $extensions[] = ".".strtolower($value); }else{ $extensions[] = strtolower($value); } } //SECTION #3 foreach($extensions as $value){ // echo '<BR>value=' . $value; // echo '<BR>extension=' . $extension; if($value == $extension){ $valid_extension = 'TRUE'; break; }else{ $valid_extension = 'FALSE'; } // echo "valid_extension= ". $valid_extension; } //SECTION #4 if ($valid_extension=='TRUE') { //echo 'valid_extension = true'; return 'TRUE'; }else{ //echo 'valid_extension = false'; return 'FALSE'; } } } } function validate_size() { $temp_file_name = trim($this->temp_file_name); $max_file_size = trim($this->max_file_size); if (isset($temp_file_name)) { $size = filesize($temp_file_name); if ($size > $max_file_size) { // echo 'filesize false'; return 'FALSE'; } else { return 'TRUE'; } } else { // echo 'temp file name false'; return 'FALSE'; } } function existing_file() { $file_name = trim($this->file_name); // echo $file_name; $upload_dir = $this->get_upload_directory(); if ($upload_dir == "upload dir ERROR") { return true; } else { $file = $upload_dir . $file_name; if (file_exists($file)) { return true; } else { return false; } } } function get_file_size() { //SECTION #1 $temp_file_name = trim($this->temp_file_name); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; //SECTION #2 if ($temp_file_name) { $size = filesize($temp_file_name); if ($size < $kb) { $file_size = "$size Bytes"; } elseif ($size < $mb) { $final = round($size/$kb,2); $file_size = "$final KB"; } elseif ($size < $gb) { $final = round($size/$mb,2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb,2); $file_size = "$final GB"; } else { $final = round($size/$tb,2); $file_size = "$final TB"; } } else { $file_size = "ERROR: NO FILE PASSED TO get_file_size()"; } return $file_size; } function get_max_size() { $max_file_size = trim($this->max_file_size); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if ($max_file_size) { if ($max_file_size < $kb) { $max_file_size = "max_file_size Bytes"; } elseif ($max_file_size < $mb) { $final = round($max_file_size/$kb,2); $max_file_size = "$final KB"; } elseif ($max_file_size < $gb) { $final = round($max_file_size/$mb,2); $max_file_size = "$final MB"; } elseif($max_file_size < $tb) { $final = round($max_file_size/$gb,2); $max_file_size = "$final GB"; } else { $final = round($max_file_size/$tb,2); $max_file_size = "$final TB"; } } else { $max_file_size = "ERROR: NO SIZE PARAMETER PASSED TO get_max_size()"; } return $max_file_size; } function validate_user() { //SECTION #1 $banned_array = $this->banned_array; $ip = trim($_SERVER['REMOTE_ADDR']); $cpu = gethostbyaddr($ip); $count = count($banned_array); //SECTION #2 if ($count < 1) { return true; } else { foreach($banned_array as $key => $value) { if ($value == $ip ."-". $cpu) { return false; } else { return true; } } } } function get_upload_directory() { //SECTION #1 $upload_dir = trim($this->upload_dir); //SECTION #2 if ($upload_dir) { $ud_len = strlen($upload_dir); $last_slash = substr($upload_dir,$ud_len-1,1); if ($last_slash <> "/") { $upload_dir = $upload_dir."/"; } else { $upload_dir = $upload_dir; } //SECTION #3 $handle = @opendir($upload_dir); if ($handle) { $upload_dir = $upload_dir; closedir($handle); } else { $upload_dir = "upload dir ERROR"; } } else { $upload_dir = "upload dir ERROR"; } return $upload_dir; } function get_upload_log_directory() { $upload_log_dir = trim($this->upload_log_dir); echo "<br /> upload log dir: ".$upload_log_dir; if ($upload_log_dir) { $ud_len = strlen($upload_log_dir); $last_slash = substr($upload_log_dir,$ud_len-1,1); if ($last_slash <> "/") { $upload_log_dir = $upload_log_dir."/"; } else { $upload_log_dir = $upload_log_dir; } $handle = @opendir($upload_log_dir); if ($handle) { $upload_log_dir = $upload_log_dir; closedir($handle); } else { $upload_log_dir = "ERROR"; echo 'no handle'; } } else { $upload_log_dir = "ERROR"; echo 'no upload dir'; } return $upload_log_dir; } function upload_file_no_validation() { //SECTION #1 $temp_file_name = trim($this->temp_file_name); $file_name = trim(strtolower($this->file_name)); $upload_dir = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size = $this->get_file_size(); $ip = trim($_SERVER['REMOTE_ADDR']); $cpu = gethostbyaddr($ip); $m = date("m"); $d = date("d"); $y = date("Y"); $date = date("m/d/Y"); $time = date("h:i:s A"); //SECTION #2 if (($upload_dir == "ERROR") OR ($upload_log_dir == "ERROR")) { return false; } else { if (is_uploaded_file($temp_file_name)) { if (move_uploaded_file($temp_file_name,$upload_dir . $file_name)) { $log = $upload_log_dir.$y."_".$m."_".$d.".txt"; $fp = fopen($log,"a+"); fwrite($fp,"$ip-$cpu | $file_name | $file_size | $date | $time"); fclose($fp); return true; } else { return false; } } else { return false; } } } function upload_file_with_validation() { //SECTION #1 $temp_file_name = trim($this->temp_file_name); $file_name = trim(strtolower($this->file_name)); $upload_dir = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size = $this->get_file_size(); $ip = trim($_SERVER['REMOTE_ADDR']); $cpu = gethostbyaddr($ip); $m = date("m"); $d = date("d"); $y = date("Y"); $date = date("m/d/Y"); $time = date("h:i:s A"); $existing_file = $this->existing_file(); //<-Add On $valid_user = $this->validate_user(); //<-Add On $valid_size = $this->validate_size(); //<-Add On $valid_ext = $this->validate_extension(); //<-Add On //SECTION #2 if (($upload_dir == "ERROR") OR ($upload_log_dir == "ERROR")) { return false; } elseif ((((!$valid_user) OR (!$valid_size) OR (!$valid_ext) OR ($existing_file)))) { return false; } else { if (is_uploaded_file($temp_file_name)) { if (move_uploaded_file($temp_file_name,$upload_dir . $file_name)) { $log = $upload_log_dir.$y."_".$m."_".$d.".txt"; $fp = fopen($log,"a+"); fwrite($fp,"$ip-$cpu | $file_name | $file_size | $date | $time \r\n"); fclose($fp); return true; } else { return false; } } else { return false; } } } } all help greatly appreciated anatak Quote Link to comment Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Wait wait wait, what exactly do you want? Quote Link to comment Share on other sites More sharing options...
anatak Posted September 4, 2009 Author Share Posted September 4, 2009 for example the folder created is Ducati_10 the image name in the database is Ducati_10_0.jpeg (Ducati_10 first picture) but the image file written to the Ducati_10 folder is ducati_10_0.jpeg Does anybody know how to preserve the capital when writing a file. I want to preserve the capital of the file I am writing Quote Link to comment Share on other sites More sharing options...
trq Posted September 4, 2009 Share Posted September 4, 2009 There are several places within that class where your file names are made lower case, remove them. Quote Link to comment Share on other sites More sharing options...
anatak Posted September 4, 2009 Author Share Posted September 4, 2009 Thanks thorpe, You are absolutely right. a classic moment of looking at the wrong place (not in the class) all solved now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.