Upload pictures form and code

A

Anonymous

Guest
I am trying to build a form that includes an upload of a picture that I want to store in a mysql database. I have 2 questions. I am a newbie trying to learn and my book doesn't seem to give proper answers.

First, what am I supposed to put for the path in $file_dir? An example? I keep getting a warning "Warning: move_uploaded_file(/tmp/fish pic.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\do_upload.php on line 10". Here is the code:


Code:
<?php
$file_dir = "/tmp";
foreach($_FILES as $file_name => $file_array) {
	echo "path: ".$file_array['tmp_name']."<br>\n";
	echo "name: ".$file_array['name']."<br>\n";
	echo "type: ".$file_array['type']."<br>\n";
	echo "size: ".$file_array['size']."<br>\n";

	if (is_uploaded_file($file_array['tmp_name'])) {
		move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy");
		echo "file was moved!<br><br>";
	}
}
?>

This is run from the following HTML form:

Code:
<html>
<head>
<title>A simple file upload form</title>
</head>
<body>
<form action="do_upload.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<p><strong>File to Upload:</strong> <input type="file" name="fileupload"></p>
<p><input type="submit" value="upload!"></p>
</form>
</body>
</html>

My second question is how do I get my pictures into mysql? I have a MySQL table already made that has a mediumblob column to store the pictures.

Cheers!
Justin
 
make a dir called c:\tmp and update your php.ini to reflect that.
 
Back
Top