Upload a photo file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
farfromrest
Forum Newbie
Posts: 11
Joined: Sun Jul 20, 2003 7:09 pm

Upload a photo file

Post by farfromrest »

excuss my sloppness ive been staring at this for hours and cant figure it out, why it wont work

here is my form:

Code: Select all

<?php
echo"
			<table cellpadding=0 cellspacing=0 class=body>
				<form enctype="multipart/form-data" action="?func=upload_listing" method="post">
					<tr>
						<td align=right class=header>
							Upload&nbsp;Picture:
						</td>
						<td>
							<input name="photo" type="file">
						</td>
					</tr>
					<tr>
						<td valign=bottom>
							<input type=hidden name=id value=1>
						</td>
						<td valign=bottom>
							<input type=submit name=submit value="Upload&nbsp;Photo">
						</td>
					</tr>
				</form>
			</table>";
?>
and here is the part to save the file

Code: Select all

<?php
if (is_uploaded_file($_FILES['photo']['tmp_name'])){
			$destanation = $_POST[id] . ".jpg";
			move_uploaded_file($_FILES['photo']['tmp_name'], $destanation); 
			print "
			<table width=100%>
				<tr>
					<td>
						<center><b>your picture has been uploaded</b></center>
					</td>
				</tr>
			</table>";
		}
		else{
			print "
			<table width=100%>
				<tr>
					<td>
						<center><b>ERROR</b></center>
					</td>
				</tr>
			</table>";
		}
?>
please help thanks, i swear if i look at this any longer im going to explode
RadixDev
Forum Commoner
Posts: 66
Joined: Sun Mar 14, 2004 11:27 am
Location: U.K.

Post by RadixDev »

echo $destination and see what that prints out.
You haven't stated the problem... :?:
farfromrest
Forum Newbie
Posts: 11
Joined: Sun Jul 20, 2003 7:09 pm

Post by farfromrest »

echo $destination and see what that prints out.
You haven't stated the problem...
the file wont up load and i get the ERROR everytime
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

farfromrest wrote:the file wont up load and i get the ERROR everytime
well give us the error message then!
farfromrest
Forum Newbie
Posts: 11
Joined: Sun Jul 20, 2003 7:09 pm

Post by farfromrest »

the file wont up load and i get the ERROR everytime
well give us the error message then!
i take it you didnt look at the code well

Code: Select all

<?php
if (is_uploaded_file($_FILES['photo']['tmp_name'])){ 
         $destanation = $_POST[id] . ".jpg"; 
         move_uploaded_file($_FILES['photo']['tmp_name'], $destanation); 
         print " 
         <table width=100%> 
            <tr> 
               <td> 
                  <center><b>your picture has been uploaded</b></center> 
               </td> 
            </tr> 
         </table>"; 
      } 
      else{ 
         print " 
         <table width=100%> 
            <tr> 
               <td> 
                  [b]<center><b>ERROR</b></center> [/b]
               </td> 
            </tr> 
         </table>"; 
      } 

?>
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

I think he meant the error that caused is_uploaded_file to fail. Obviously ERROR is not going to help narrow anything down. Generally it is a lot easier to help someone if you have some idea of what the problem is.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

magicrobotmonkey wrote:I think he meant the error that caused is_uploaded_file to fail. Obviously ERROR is not going to help narrow anything down. Generally it is a lot easier to help someone if you have some idea of what the problem is.
exactly, i didnt mean to cause offence by my "obvious" answer, but the reason people come to the forums is for help and it makes "our" job harder, if we dont know the error message, as this will more than often tell you exactly what is wrong with your script and line number.

I believe this is also in posting guidelines.........
User avatar
samsbox
Forum Newbie
Posts: 4
Joined: Mon Apr 19, 2004 2:52 am
Location: Telford, UK

Post by samsbox »

erm, Im not too sure, but should'nt

$_POST[id]

be

$_POST["id"]

:?
Post Reply