2012-03-29 31 views
1

こんにちは私は試してアップロードするときに画像が選択されていないエラーを取得し続けている、アップロードフォームは間違いなくコードに何かが間違っている必要があります理由を見ますか?アップロード画像php mysql binary

<?php 


// Create MySQL login values and 
// set them to your login information. 
$username = "**"; 
$password = "**"; 
$host = "**"; 
$database = "**"; 

// Make the connect to MySQL or die 
// and display an error. 
$link = mysql_connect($host, $username, $password); 
if (!$link) { 
     die('Could not connect: ' . mysql_error()); 
    } 

    // Select your database 
    mysql_select_db ($database); 

    session_start(); 
    if(!isset($_SESSION['username'])) 
    { 
      die('You have no access to this page.'); 
    } 
    else{ 
    $username = $_SESSION['username']; 
    // Make sure the user actually 
    // selected and uploaded a file 
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

    // Temporary file name stored on the server 
    $tmpName = $_FILES['image']['tmp_name']; 

    // Read the file 
    $fp  = fopen($tmpName, 'r'); 
    $data = fread($fp, filesize($tmpName)); 
    $data = addslashes($data); 
    fclose($fp); 


    // Create the query and insert 
    // into our database. 
    $query = "INSERT INTO Members WHERE username = '$username' "; 
    $query .= "(image) VALUES ('$data')"; 
    $results = mysql_query($query, $link); 

    // Print results 
    print "Thank you, your file has been uploaded."; 

} 
else { 
print "No image selected/uploaded"; 
} 
} 
    // Close our MySQL Link 
    mysql_close($link); 
    ?> 
+1

「var_dump($ _ FILES)」はあなたに何を与えますか?空のファイルを渡したか、またはファイル入力に正しい名前を与えなかったか( '' image "'が必要です)。 – Halcyon

+0

addslashesではなく、mysql_real_escape_stringを使用して、SQLインジェクションから完全に保護されていることを確認してください。 – dsas

答えて

0

おそらくあなた<form>タグがenctypeパラメータを欠いています。これは次のようになります:

<form action="index.php?action=upload" method="post" enctype="multipart/form-data"> 
関連する問題