SitePoint Sponsor |
|
User Tag List
Results 1 to 10 of 10
-
Apr 26, 2009, 07:27 #1
- Join Date
- Jun 2007
- Location
- Plymouth uk
- Posts
- 313
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how do i convert this to send photo to my server
ok i have this form which sends all details to database and emails me with attachment if they have a photo
instead of that i wanted the photo to go to my server in a folder where all photos stored
this is my form
PHP Code:<form action="add1.php" method="post" enctype="multipart/form-data">
<table width="604" border="0" cellspacing="5">
<tr>
<td><span class="style2">Name: <span class="style3">not shown</span></span></td>
<td>
<div class="style2">
<input name="name" type="text" id="name" size="30" />
</div></td>
</tr>
<tr>
<td><span class="style2">Email:</span> not shown</td>
<td><input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td><span class="style2">Tel:</span></td>
<td><input name="tel" type="text" id="tel" size="15" /></td>
</tr>
<tr>
<td><span class="style2">Lost/Found:</span></td>
<td><select name="state">
<option value="lost">LOST</option>
<option value="found">FOUND</option>
</select>
<br /></td>
</tr>
<tr>
<td><span class="style2">Dog/Cat:</span></td>
<td><select name="type">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
</select>
<br /></td>
</tr>
<tr>
<td><span class="style2">Area: Found or Lost</span></td>
<td><input name="area" type="text" id="area" size="30" /></td>
</tr>
<tr>
<td valign="top"><span class="style2">Description:</span></td>
<td><textarea name="desc" cols="30" rows="6" id="desc"></textarea></td>
</tr>
<tr>
<td>Photo: Rename your photo to see below</td>
<td><input type="file" name="pic" /></td>
</tr>
<tr>
<td>Anti-Spam Question. How many legs on a Dog ?</td>
<td><input name="leg" type="text" id="leg" size="3" /></td>
</tr>
<tr>
<td>Picture Number as below if no pic then enter 1 for dog 2 for cat</td>
<td><input name="pnum" type="text" id="pnum" size="3" /></td>
</tr>
<tr>
<td><input name="send" type="submit" id="send" onclick="MM_validateForm('name','','R','email','','NisEmail','tel','','RisNum','area','','R','desc','','R');return document.MM_returnValue" value="Send" /></td>
</tr>
</table>
</form>
</div>
PHP Code://This gets all the other information from the form
$state=$_POST['state'];
$type=$_POST['type'];
$area=$_POST['area'];
$desc=$_POST['desc'];
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$pnum=$_POST['pnum'];
$date = date("d-m-Y");
$pname=$pnum.".jpg";
// Connects to your Database
$dbh=mysql_connect("localhost", "vcd", "57") or die('I cannot connect to database because: ' .mysql_error()) ;
mysql_select_db("pets");
//Writes the information to the database
mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')");
//compose the mail message
$msg= "New Record\n Region: $region, Name: $name, Email: $email ";
//send the mail
mail('d@gmail.com','New Record',$msg)
?>
Dougan old man of 60 trying to keep up with the youngsters he he
http://lostpetsplymouth.net16.net
-
Apr 26, 2009, 07:45 #2
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use move_uploaded_file() to save the file to a specific directory.
-
Apr 26, 2009, 07:50 #3
- Join Date
- Jun 2007
- Location
- Plymouth uk
- Posts
- 313
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yes i read that some where but cant remeber how to do that
cheers
Dougan old man of 60 trying to keep up with the youngsters he he
http://lostpetsplymouth.net16.net
-
Apr 26, 2009, 08:12 #4
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The official php manual is always a great place to learn more about a function. You just goto
php.net/FUNCTION_NAME_HERE
for example
www.php.net/move_uploaded_file
There's usually a lot of user posted comments as well for most functions. This may help too
http://www.php.net/manual/en/feature...ost-method.php
-
Apr 26, 2009, 08:28 #5
- Join Date
- Jun 2007
- Location
- Plymouth uk
- Posts
- 313
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks again for info had a look dont begin to understand it
but all the examples seem to have just upload on a form by itself
where i have a few fields
cheers
Dougan old man of 60 trying to keep up with the youngsters he he
http://lostpetsplymouth.net16.net
-
Apr 26, 2009, 11:54 #6
- Join Date
- Jul 2008
- Posts
- 213
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This wouldn't matter.
PHP Code:$state=$_POST['state'];
$type=$_POST['type'];
$area=$_POST['area'];
$desc=$_POST['desc'];
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
$pnum=$_POST['pnum'];
$date = date("d-m-Y");
$pname=$pnum.".jpg";
move_uploaded_file($_FILES['pic']['tmp_name'], 'path/to/your/uploads/'.$pname);
# rest of your code
-
Apr 26, 2009, 12:08 #7
- Join Date
- Jul 2008
- Posts
- 81
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please filter your variables. :P
-
Apr 26, 2009, 20:23 #8
- Join Date
- Apr 2009
- Posts
- 90
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This may help:
http://www.tizag.com/phpT/fileupload.php
-
Apr 27, 2009, 02:56 #9
- Join Date
- Jun 2007
- Location
- Plymouth uk
- Posts
- 313
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:move_uploaded_file($_FILES['pic']['tmp_name'], 'upload/'.$pname);
Doug
ok photo now goes to server but no name just .jpg when it should be eg 7.jpgLast edited by dougvcd; Apr 27, 2009 at 05:11. Reason: more info
an old man of 60 trying to keep up with the youngsters he he
http://lostpetsplymouth.net16.net
-
Apr 27, 2009, 07:44 #10
- Join Date
- Jun 2007
- Location
- Plymouth uk
- Posts
- 313
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks to all now sorted
cheers
Dougan old man of 60 trying to keep up with the youngsters he he
http://lostpetsplymouth.net16.net
Bookmarks