I need to upload file to database using this code

I need to upload file to database using this code. because by using code i can only attach file to mail but i can’t store it on database please help me

$semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
        		$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
    $message .= "--{$mime_boundary}\n";
    for($x=0; $x < count($files); $x++){
        $file = fopen($files[$x]['tmp_name'], "rb");
        $data = fread($file, filesize($files[$x]['tmp_name']));
        $data = chunk_split(base64_encode($data));
        $name = $files[$x]['name'];
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" . 
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
        $message .= "--{$mime_boundary}\n";
    $ok = mail($to, $subject, strip_tags($message), $headers);
        echo "<p>mail sent</p>";
        echo "<p>mail could not be sent!</p>";

What attempts have you made to modify your code to update your database?

submitted data is stored in db. i don’t know what variable should i take and assign it while inserting doc file to db.

So you want to take the data from one database and store it in another db?

no i have a form contains data and file. i need both to save in database. but now i dont know how to save file but i am saving data after submitting form. what i need is here i want to store file also in db.

Have a browse down the forum, there have been some topics recently on file uploads with some sample code that you can use to get started, then come back with specific issues about anything that isn’t clear.

Do you actually want to store the file in the database, or do you want to move it somewhere in the file system and store a pointer to it in the database? I recall quite a back-and-forth about which is the best option, without either being a clear winner.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.