Hey all.
Har fundet denne dejlige uploading af filer.
Dog vil jeg kun have den til at kunne acceptere filer af images.
jpg,gif,png
Nogen der kan hjælpe mig videre?.
Her godkender den .rar mv.
Filen.php
- <?php
- include("config.php");
- if(isset($_FILES['files'])){
- $errors= array();
- foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
- $file_name = $key.$_FILES['files']['name'][$key];
- $file_size =$_FILES['files']['size'][$key];
- $file_tmp =$_FILES['files']['tmp_name'][$key];
- $file_type=$_FILES['files']['type'][$key];
- if($file_size > 2097152){
- $errors[]='Filstørrelse skal være mindre end 2 MB';
- }
- $query="INSERT into tp_fotogalleri (`brugernavn`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('". $_SESSION['brugernavn'] ."','". $file_name ."','". $file_size ."','". $file_type ."'); ";
- $desired_dir="upload/";
- if(empty($errors)==true){
- if(is_dir($desired_dir)==false){
- mkdir("$desired_dir", 0700); // Create directory if it does not exist
- }
- if(is_dir("$desired_dir/".$file_name)==false){
- move_uploaded_file($file_tmp,"upload/".$file_name);
- }else{ //rename the file if another one exist
- $new_dir="upload/".$file_name.time();
- rename($file_tmp,$new_dir) ;
- }
- mysql_query($query);
- }else{
- print_r($errors);
- }
- }
- if(empty($error)){
- echo "Success";
- }
- }
- ?>
-
-
- <form action="" method="POST" enctype="multipart/form-data">
- <input type="file" name="files[]" multiple/>
- <input type="submit"/>
- </form>
Indlæg senest redigeret d. 23.09.2013 09:57 af Bruger #17554