Jump to content

Passing a file to a funcion with user input


Andy-T

Recommended Posts

Hi,

Maybe someone would be good enough to give me a helping hand.

I just need a button that passes a static file name to a fuction, there's probably more to it than I know. I can do it through uploading the file but I don't want users to be able to choose the file, just hit the button to make it happen :-).

Here's the form that lets me upload and call the fuction.

<form enctype= "multipart/form-data" name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<input name="textfile" type="file" value="YourFile.txt" class="arial12" style="width: 305px; border : 1px solid black;" >
<input type="submit" name="importtextfilesubmit" value="Import" width="80">
</form>

I tried adding [b]value="YourFile.txt"[/b] but this did'nt help :-(.

Here's the fuction I need to pass to.

function importcommaseparateddata($textfile, $textfile_name, &$status, &$newusers, $existingusers) {
global $languagearray;

if($textfile=="none" OR $textfile=="") { //No file selected
$status .= $languagearray[15];
} else { /* File was selected correctly */
if(move_uploaded_file ($textfile, "./".$textfile_name)==true) { /* Upload okay */
createhtaccess($status); /* .htaccess anlegen */
$textfilehandle = fopen ($textfile_name, "r"); /* open transferred textfile */
while ($data = fgetcsv ($textfilehandle, 1000, ",")) { /* read and parse commaseparated data */
$newuser = $data[0];
$newpass = $data[1];
if (checkimports($newuser, $newpass, $status, $existingusers) == true) { /* Importierte Daten prüfen */
adduser($newuser, $newpass, $status, $newusers); /* Userinfo in $newusers ablegen */
} //endif
} //endwhile
createhtpasswd($newusers, $status, $existingusers); /* user in .htpasswd eintragen */
fclose ($textfilehandle);
if(unlink($textfile_name)==false ) {
$status .= $languagearray[19].$textfile_name.$languagearray[20];
} //endif
} else {
$status .= $languagearray[18];
} //endif
} //endif
} //EndOfFunction


I'm new to any real kind of web programing so any help will be appreacated.

Andy-T

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.