Upload pictures form and code

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
php-forum Fan User
php-forum Fan User
Posts: 50
Joined: Fri Apr 28, 2006 4:47 pm
Location: Pittsburgh, PA

Wed Jun 07, 2006 12:21 pm

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: Select all

$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: Select all

<title>A simple file upload form</title>
<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>
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.

People are not the pinacle of evolution. They are merely an abherent sidebranch of fish evolution, which explains why women are attracted to shiny bits of metal.
User avatar
Posts: 826
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Wed Jun 07, 2006 7:54 pm

make a dir called c:\tmp and update your php.ini to reflect that.
Post Reply