Page 1 of 1

PHP Upload files concern.

Posted: Mon Apr 26, 2010 11:48 pm
by dunk_6
Hi all,

I have concerned regarding upload file. when im searching in the net, i found that, to upload u need

Code: Select all

<form method="post" enctype="multipart/form-data"> 
in the form tag. And used

Code: Select all

move_uploaded_file(filename,filelocation)
to move into the upload folder.

Can we still upload without this

Code: Select all

enctype="multipart/form-data"
in the form tag? And for

Code: Select all

move_uploaded_file(filename,filelocation)
the filename is it only

Code: Select all

$_FILES["faillampiran"]["name"]
?? can't i change or used from user defined name?

thank you

Re: PHP Upload files concern.

Posted: Tue Apr 27, 2010 1:04 am
by requinix
Yes, you need encoding=multipart/form-data to upload files normally.

No, you can put whatever you want for the "filelocation".

Re: PHP Upload files concern.

Posted: Tue Apr 27, 2010 4:01 am
by dunk_6
tasairis wrote:Yes, you need encoding=multipart/form-data to upload files normally.

No, you can put whatever you want for the "filelocation".
so that's mean i need to include them each time wanna use this function?? is there any other way to upload files coz i think it's hard to deal with 2 form tags.

Code: Select all

 <form> 
     //other input text box here 
     <form encoding=multipart/form-data >
          //form to do upload here
     </form>
</form>
thank you.
is it possible to do this way?

Re: PHP Upload files concern.

Posted: Tue Apr 27, 2010 4:11 am
by requinix
How is it hard? It's a second or two of typing.

Re: PHP Upload files concern.

Posted: Wed Apr 28, 2010 1:25 am
by dunk_6
tasairis wrote:How is it hard? It's a second or two of typing.
it's not bout typing issue, it's about understanding why the code didnot run..

ok if i want write it like this, for example, i want to insert start date and other infos. i put that in the form. Later i wanna add function to upload file. since it has it's own form tag, i juz add the upload form into the first form. But when i run, it seems that only upload button was functioning, another :

Code: Select all

 
<form name="form" id="form" method="post">
  <table>
   <tr>
        <td><?php echo "Start Date"; ?></td>
        <td>:</td>
        <td><input type="text" name="startdate" id="startdate"  maxlength="25" size="25" readonly="" value="<?=$startdate;?>"/>
                &nbsp;<a href='javascript:NewCal("startdate","ddmmyyyy",false,24)'><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"/>&nbsp;<span class="style1">*</span></a></td>
   </tr>
   </table>
    <form method="post" name="form" id="form" enctype="multipart/form-data"> 	
         <table>
	<tr><td><input type="hidden" name="MAX_FILE_SIZE" value=""> </td> </tr>
	<tr><td> Please choose a file</td><td>:</td></tr>
	<tr>
	<input type="file" size="50" name="faillampiran" alt="faillampiran" id="faillampiran" 1value= "<?=$faillampiran;?>" />
	<tr align = "center"><td colspan = "3"><input type="submit" value="Upload" name="btnupload"/></td></tr>
	</tr>
         </table>
    </form>

<input type='submit' value='<?php echo get_string('btnsave','course'); ?>' name="btnsave" 1onclick="alert()" > &nbsp;	
</form>
it seems that, only one button is fuctioning. Why is that?

thx