Fukzzs miniblogs

  • Fukzzs
    0

    Labvakar.
    Tātad izmantojot šo pamācību jeb drīzāk kodu http://techstream.org/Web-Development/PHP/Mu...h-PHP-and-MySQL
    Man failu dati nesaglabājās datubāzē, bet paši faili tiek augšupielādēti un ar to viss ir kārtībā. Kādēļ datubāzē nesaglabājās?
    Lūk kods.


    <?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[]='File size must be less than 2 MB';
    }
    $username = "root";
    $password = "*******";
    $hostname = "localhost";
    $dbhandle = mysql_connect($hostname, $username, $password) 
    or die("Unable to connect to MySQL");
    echo "Connected to MySQL<br>";
    $selected = mysql_select_db("fukzzs",$dbhandle) 
    or die("Could not select fukzzs");
    $result = mysql_query("INSERT into test (`USER_ID`,`FILE_NAME`,`FILE_SIZE`,`FILE_TYPE`) VALUES('$user_id','$file_name','$file_size','$file_type'); ");
    $desired_dir="user_data"; 
    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,"user_data/".$file_name);
    }else{ //rename the file if another one exist
    $new_dir="user_data/".$file_name.time();
    rename($file_tmp,$new_dir) ;
    }
    mysql_query($result);
    }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>

     

     

    • mad
      0

      Parādi datubāzes struktūru.

    • mad
      0

      BTW noteikti nevajag likt mysql konekcijas izveidi ciklā. Izveido to sākumā pirms cikla. Tas gan nav iemesls kāpēc šis nestrādā.

Atpakaļ Uz augšu