Mistake of error
-
In fact, I have three references, which I've pressed for certain files. It's all good to get out of here just help me make a mistake. I mean, if there was an exucutable, and there was no file on the server, I'd like to take out the "Programs aren't found" if the photos weren't found or the documents. PHP:
$types = array( "executable" => array( "exe", "msi" ),"photo" => array( "jpg", "png","gif" ),"document" => array( "doc", "docx", "pdf" ),);
$type = $types[ $_POST[ "file_type" ] ]; if( $type ) { show_files_type( $type ); } else { echo "Ошибка"; } function show_files_type ($type) { $connect = ftp_connect('********'); $connect_login = ftp_login($connect, '****', '******'); ftp_chdir($connect, '**********/'); $list_files = ftp_nlist($connect, "."); if (count($list_files) !== 1) { for ($i = 0; $i < count($list_files); $i++) { if ($list_files[$i] !== "upload") { $extension = substr(strrchr($list_files[$i], '.'), 1); foreach ($type as $type_val) { if ($extension == $type_val) { $time_modify = date("Y-m-d H:i:s", ftp_mdtm($connect, $list_files[$i])); $size_file = substr(((ftp_size($connect, $list_files[$i]) / 1024) / 1024),0,5)." Мб"; $link_download_file = '<a href="*************/'.$list_files[$i].'"><button class="btn btn-success"><span class="glyphicon glyphicon-cloud-download"></span> Скачать файл</button></a>'; $remove_file = '<a onclick="delete_file(this.id)" id="'.$list_files[$i].'"><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Удалить файл</button></a>'; echo '<tr><td>'.$list_files[$i].'</td><td>'.$time_modify.'</td><td>'.$size_file.'</td><td>'.$link_download_file.'</td><td>'.$remove_file.'</td></tr>'; } } } } } ftp_close($connect); }
-
I mean, if there was an exucutable and there was no file on the server.
What do you mean, "have"?
If I've got it right, maybe it'll help you make a decision:
foreach ($type as $type_set) {
$flsExsts = false; foreach ($list_files as $file) { if($file !== 'upload') { $extension = substr(strrchr($file, '.'), 1); if($extension == $type_set) { $time_modify = date("Y-m-d H:i:s", ftp_mdtm($connect, $file)); $size_file = substr(((ftp_size($connect, $file) / 1024) / 1024), 0, 5)." Мб"; $link_download_file = '<a href="*************/'.$file.'"><button class="btn btn-success"><span class="glyphicon glyphicon-cloud-download"></span> Скачать файл</button></a>'; $remove_file = '<a onclick="delete_file(this.id)" id="'.$file.'"><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Удалить файл</button></a>'; echo ' <tr> <td>'.$file.'</td> <td>'.$time_modify.'</td> <td>'.$size_file.'</td> <td>'.$link_download_file.'</td> <td>'.$remove_file.'</td> </tr>'; $flsExsts = true; } } } if(!$flsExsts) { echo 'Files of type '.$type_set.' does not exists'; } }
The point is, we don't count the files first, and then, within each cycle, we check whether the expansion file fits, and vice versa, first we're on the list of types of files and inside the cycle, we consider the number. If the number after the recosting cycle is zero, we shall withdraw the notification.
Actually, it's not a good idea to check that the file matches a certain type of expansion. You can change the expansion of the file and the crypt will recognize it differently. If it's interesting and time, it's better to check the conformity through Mime types. There's a great expansion to work with them at the PHP. http://us1.php.net/manual/ru/book.fileinfo.php ♪ More specific implementation can be read http://us1.php.net/manual/ru/function.finfo-file.php ♪