Page 1 of 1

Upload a photo file

Posted: Wed Apr 14, 2004 12:21 am
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

Posted: Wed Apr 14, 2004 1:30 am
by RadixDev
echo $destination and see what that prints out.
You haven't stated the problem... :?:

Posted: Wed Apr 14, 2004 9:04 am
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

Posted: Wed Apr 14, 2004 9:05 am
by malcolmboston
farfromrest wrote:the file wont up load and i get the ERROR everytime
well give us the error message then!

Posted: Wed Apr 14, 2004 2:11 pm
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>"; 
      } 

?>

Posted: Wed Apr 14, 2004 2:14 pm
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.

Posted: Thu Apr 15, 2004 7:08 am
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.........

Posted: Mon Apr 19, 2004 5:21 am
by samsbox
erm, Im not too sure, but should'nt

$_POST[id]

be

$_POST["id"]

:?