0

I'm using an html form to submit data directly into a mysql database using a php script. For some reason the pictures will not be uploaded fully into the database. This is when I don't use a multipart/form-data tag. When that occurs the pictures partially upload but when I put the tag in the pictures do not upload at all. Here is the html for the form. I believe that the script works because the pictures partially upload. Any help will be appreciated because I'm getting wicked frustrated. Here is the code for the form with the mutlipart/form-data info:

<div id="slform">

<h1 align="center">Post an Available Sub-Lease</h1>

<form action="signup_ac.php" enctype="multipart/form-data" method="post" name="tempslform"  onsubmit="return validate_form(tempslform) && checkform(email) && validate(tempslform)"> 
<span>Rent:</span> $ <input name="rent" tabindex="1" size="3" maxlength="10" type="text" /><br/>
<span>Listing Title:</span> <input name="listingtitle" tabindex="1" size="30" maxlength="70" type="text" /><br/> 
<span>Street and Cross Street:</span> <input name="stcst" tabindex="1" size="20" maxlength="40" type="text" /><br /> 
<span>Listing Description:</span><br /> 
<textarea name="listdesc" tabindex="1" cols="80" style="width: 60%" rows="10" type="text" align="center"></textarea><br /> 
<span>Reply to: </span> <input name="email" tabindex="1" class="req df" size="30" value="Your email address" maxlength="60" type="text" /> 
<input name="retype" tabindex="1" size="30" value="Retype email address" maxlength="60" type="text" /><br/>
<span>Street:</span>:
<input name="street" tabindex="1" size="20" maxlength="80" type="text" /> 
<span>Nearest Cross Street:</span> <input name="cstreet" tabindex="1" size="20" maxlength="80" type="text" /><br/>
<span>City:</span> <input name="city" tabindex="1" size="20" maxlength="80" type="text" />
<span class="std">State:</span> <input name="state" tabindex="1" size="3" maxlength="10" type="text" /><br/>
<input type="file" name="pic1" /><input type="file" name="pic2" /><br />
<input type="file" name="pic3" /><input type="file" name="pic4" /><br /> 
<button tabindex="1" type="submit" value="submit">Continue</button> </form>
</div>

Thanks ahead of time for any help. If you need any additional information let me know.

Edited by ptara1: bad writing

4
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by TechySafi
0

What do you mean with "partially upload"? Does part of them get into the database? Show the receiving script and the CREATE TABLE statements for the images table.

0

By partially uploaded I mean 10 bytes of the 100+ for the picture are uploaded. I know it's bad habit to upload pictures directly into the database but for now I would like to do it.

The table is created and contains four longblob binary objects named pic1, pic2, pic3, and pic4. Do you need the create table mysql?

The script for inserting the pictures into the database are as follows:

<?php
include('connect.php');

$tbl_name=tempslform;

$confirmcode = md5(uniqid(rand()));
$rent = $_POST ;
$listingtitle = $_POST ;
$stcst = $_POST ;
$listdesc = $_POST ;
$email = $_POST ;
$retype = $_POST ;
$street = $_POST ;
$ctstreet = $_POST ;
$city = $_POST ;
$state = $_POST ;
$date = date("Y-m-d");
$pic1 = $_POST ;
$pic2 = $_POST ;
$pic3 = $_POST ;
$pic4 = $_POST ;


$sql="INSERT INTO $tbl_name (confirmcode, rent, listingtitle, stcst, listdesc, email, retype, street, ctstreet, city, state, date, pic1, pic2, pic3, pic4) VALUES ('".$confirmcode."', '".$rent."', '".$listingtitle."', '".$stcst."', '".$listdesc."', '".$email."', '".$retype."', '".$street."', '".$ctstreet."', '".$city."', '".$state."', '".$date."', '".$pic1."', '".$pic2."', '".$pic3."', '".$pic4."')";

$result=mysql_query($sql);

?>

I have some other parts about sending an email and confirming the listing but that all works. Currently, when I don't include the multipart/data-form in the form tag, I get a partial upload, a few bytes. When I include it nothing uploads.

0

Wouldn't it make your database more efficient if you stored the image file in the server and just stored the image's address in the database instead?

0

That's what I've heard, but I'm setting it up like this right now because I had this in place. If I can't figure it out in a day or two I'll probably try just storing the picture on the server like you said....but this isn't a discussion about whether or not I should save the images in the database or on the server.

Wouldn't it make your database more efficient if you stored the image file in the server and just stored the image's address in the database instead?

0

Wouldn't it make your database more efficient if you stored the image file in the server and just stored the image's address in the database instead?

You don't make your database more efficient with not storing pictures in it. That is rubbish. You make it more efficient by good design and careful indexing. There are lots of good reasons to have images in the database, one being coding efficiency.
Your upload code is wrong. To load pictures into the database you have to upload them as a file with your $_POST array containing the file name. Then you can read it from the local server into a variable and feed it to the mysql server. Google for "PHP file upload".

0

I've started to put together a file upload script into a directory as suggested. I created a directory and am trying to upload the picture but I can't due to an error with this appearing:

Warning: move_uploaded_file(pics/signpg.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\hosting\

and another one:

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php64A.tmp' to 'pics/signpg.jpg' in D:\hosting\

I include a connect function that works on other scripts. Any idea what the problem is exactly?

You don't make your database more efficient with not storing pictures in it. That is rubbish. You make it more efficient by good design and careful indexing. There are lots of good reasons to have images in the database, one being coding efficiency.
Your upload code is wrong. To load pictures into the database you have to upload them as a file with your $_POST array containing the file name. Then you can read it from the local server into a variable and feed it to the mysql server. Google for "PHP file upload".

0

Figured out I had to change permissions on the directory to make it writable. Just wondering if anyone has figured out how to directly put the binary objects into the database so I can upload multiple pictures easily at once.

I've started to put together a file upload script into a directory as suggested. I created a directory and am trying to upload the picture but I can't due to an error with this appearing:

Warning: move_uploaded_file(pics/signpg.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in D:\hosting\

and another one:

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php64A.tmp' to 'pics/signpg.jpg' in D:\hosting\

I include a connect function that works on other scripts. Any idea what the problem is exactly?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.