Php script won't do form file upload.

liunx

Guest
I am totally frustrated messing with this so maybe some of you guys will figure this out. The new site that I am working on has a form that allows a photo to be uploaded and stored in a directory on my host's server. The html form is submitted to a php script that processes it. The file will not upload and I get the following error...

Warning: Unable to open '' for reading: No such file or directory in /home/triad/www/www/submitprocessor.php on line 35

The images directory has the permissions set to 777. Here is the form html...

<!--HTML FORM SUBMIT-->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Triad Friendly Homes-Submit your home to the photo listings.</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href=http://www.htmlforums.com/archive/index.php/"triadfriendlyhomes.css">
</head>
<body>
<table class="white" align="center" cellpadding="15" cellspacing="0">
<tr>
<td><fieldset><legend>Have your home listed on <span class="bold">Triad Friendly Homes.</span></legend><form name="homesubmit" method="post" action="submitprocessor.php" enctype="multipart/form-data">
For Sale By Owner<input type="radio" name="forsaleby" value="fsbo">
Realtor or Broker<input type="radio" name="forsaleby" value="realtor"><br><br>
First Name <input type="text" name="first"> Last Name <input type="text" name="last"><br><br>
E-mail Address <input type="text" name="email"> <span class="red">*REQUIRED</span><br><br>
Phone Number <input type="text" name="phone"><br><br>
<hr width="100%" size="1">
Location of Home:<br><br>
County <select name="counties">
<option value="Alamance">Alamance
<option value="Caswell">Caswell
<option value="Davidson">Davidson
<option value="Davie">Davie
<option value="Forsyth">Forsyth
<option value="Guilford">Guilford
<option value="Montgomery">Montgomery
<option value="Randolph">Randolph
<option value="Rockingham">Rockingham
<option value="Stokes">Stokes
<option value="Surry">Surry
<option value="Yadkin">Yadkin
</select><br><br>
City or Locale <input type="text" name="city"><br><br>
<hr width="100%" size="1">
Lot Size <input type="text" name="lotsize"><br><br>
Square Feet of Home <input type="text" name="squarefeet"><br><br>
Number of Bedrooms <input type="text" name="bedrooms"><br><br>
Number of Baths <input type="text" name="baths"><br><br>
City Utilities (sewer & water) yes <input type="radio" name="utilities" value="yes"> no <input type="radio" name="utilities" value="no"><br><br>
City Taxes yes <input type="radio" name="taxes" value="yes"> no <input type="radio" name="taxes" value="no"><br><br>
Price <input type="text" name="price"><br><br>
Comments About Home:<br>
<textarea rows="10" cols="50"></textarea>
<hr width="100%" size="1">
Upload your photo.
<!--FILE UPLOAD-->
<input type="file" name="usersphoto"><br><br>
<!--END FILE UPLOAD-->
Yes, I have read the terms of agreement.<input type="checkbox" name="termsofagree" value="yes"><br><br>
<input type="reset" name="resetform" value="Reset Form">
<input type="submit" name="submitform" value="Click To Submit">
</form></fieldset></td>
</tr>
</table>
</body>
</html>

Here is the php script(NOT QUIET FINISHED!)The file upload part is towards the bottom...

//PHP FORM PROCESSOR
<?php
//DECLARE VARIABLES
$seller=$_POST['forsaleby'];
$first=$_POST['first'];
$last=$_POST['last'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$counties=$_POST['county'];
$city=$_POST['city'];
$lotsize=$_POST['lotsize'];
$squarefeet=$_POST['squarefeet'];
$bedrooms=$_POST['bedrooms'];
$baths=$_POST['baths'];
$utilities=$_POST['utilities'];
$citytaxes=$_POST['citytaxes'];
$price=$_POST['price'];
$comments=$_POST['comments'];
$termsofagree=$_POST['termsofagree'];
$submitform=$_POST['submitform'];
$to="[email protected]";
$message="$first $last has submitted a home to Triad Friendly Homes.\n Their email address is $email. \n Their phone number is $phone.\n They are selling as a $seller.";

//MAIL TO WEBMASTER

if ($_POST['email']) {
mail($to, "Home submit form.", $message, "From: $email");
echo "Thanks for submitting your home.";
}
else {
echo "Please fill in your email address.";
}

//UPLOAD PHOTO

if(copy($_FILES ['usersphoto']['temp_name'], "/home/triad/www/www/images/" . $_FILES ['usersphoto']['name'])){
print "The photo upload was successful.";
}
?>

Thanks for having a look.:rocker: :confused:Here's what I got:


$base_path = "/home/www/folder/images/".$_FILES['image']['name'];
copy($_FILES['image']['tmp_name'], $base_path);
chmod ($base_path, 0644);

$image_path = "/folder/images/" . $_FILES['image']['name'];


The $image_path is what I put in the database.Your code worked Karinne! I am still totally stumped though. Your code basically declares the base path in a variable and then submits the variable into the "copy" part of the code. My code is almost identical except it doesn't use the variable to define the base path in advance. Does that make sense? Is $base_path a predefined variable in PHP or is it one you defined? Hopefully these questions don't sound too silly but I just started learning PHP about a week ago. If anyone can tell me what is causing my code to not work I would love to hear it. Thanks very much Karinne! :D:D :D :D :D :D :D :D :D

I could shoot myself right now. All these hours trying to figure out why my code wouldn't work because I abbreviated ['tmp_file'] wrong. I typed it ['temp_file']. Oh well. :rocker:Did it again!!
['tmp_name'] not ['tmp_file']

:DThat great!!! I always do that... I've got a bunch of thread on here that I've answered myseld! :D

At least you found that error ;)
 
Back
Top