Announcement

Collapse
No announcement yet.

Help with an upload script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with an upload script

    Could somebody help me to remove the password feature out of this script & to rename the "$ADMIN[directory]" variable to "$files"? Please!

    I've tried myself but i keep getting errors. So i've decided i'll come and ask on here!

    <?php
    $ADMIN[RequirePass] = "No";
    $ADMIN[Password] = "PASSWORD";
    $ADMIN[UploadNum] = "5";
    $ADMIN[directory] = "FILES";
    if($doupload) {
    if($ADMIN[RequirePass] == "Yes") {
    if($password != "$ADMIN[Password]") {
    ?>
    <P align="center">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD WIDTH="100%">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
    <TR>
    <TD COLSPAN="2">
    <font color="#FF4400"><b>Invalid Password...</b></font>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </P>
    <?php
    exit();
    }
    }
    $num = 0;
    while($num < $ADMIN[UploadNum]) {
    $num++;
    $picture = "fileup$num"."_name";
    $picture1 = $$picture;
    $picture2 = "fileup$num";
    $picture3 = $$picture2;
    if($picture3 != "none") {
    $filesizebtyes = filesize($picture3);
    $ok = 1;
    if($filesizebtyes < 10) {
    $error .= "<font color='#FF4400'><b>Error uploading (file size lower than 10 bytes) for file $num</b></font><BR>";
    $ok = 2;
    }
    if(file_exists("$ADMIN[directory]/$picture1") OR $ok == 2) {
    $error .="<font color='#FF4400'><b>File name already exists for file $num</b></font><BR>";
    } else {
    copy ($picture3, "$ADMIN[directory]/$picture1");
    $error .="File $num has been uploaded...<BR>";
    }
    }
    }
    if(!$error) {
    $error .= "<font color='#FF4400'><b>No files have been selected for upload...</b></font>";
    }
    ?>
    <P align="center">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD WIDTH="100%">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
    <TR>
    <TD COLSPAN="2">
    <FONT SIZE="-1" FACE="Verdana"><?php echo $error; ?></FONT>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </P>
    <?php
    exit();
    } else {
    $num = 0;
    while($num < $ADMIN[UploadNum]) {
    $num++;
    $html .= "<TR>
    <TD WIDTH=\"25%\">
    <FONT SIZE=\"-1\" FACE=\"Verdana\">File $num:</FONT></TD>
    <TD WIDTH=\"75%\">
    <INPUT NAME=\"fileup$num\" TYPE=\"file\" SIZE=\"25\">
    </TD> ";
    }
    ?>
    <FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $filename ?>?action=membersarea_uploadfiles" METHOD="POST">
    <P align="center">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD WIDTH="100%">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
    <TR>
    <TD COLSPAN="2">
    <B><FONT SIZE="-1" FACE="Verdana">Select Files</FONT></B>
    </TD>
    </TR>
    <?php echo $html; ?>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </P>
    <?php
    if($ADMIN[RequirePass] == "Yes") {
    ?>
    <P align="center">
    <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD WIDTH="100%">
    <TABLE WIDTH="300" BORDER="0" CELLSPACING="1" CELLPADDING="2">
    <TR>
    <TD WIDTH="33%">
    <B><FONT SIZE="-1" FACE="Verdana">Password:</FONT></B>
    </TD>
    <TD WIDTH="67%">
    <INPUT NAME="password" TYPE="password" SIZE="25">
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </P>
    <?php
    }
    ?>
    <P align="center"><INPUT NAME="doupload" TYPE="submit" VALUE="Upload File (s)"></P>
    </FORM>
    <?php
    exit();
    }
    ?>

    Thanks to anyone that does help me!

  • #2
    not much time atm, so i can't test what i write

    first off you should use [*PHP] [*/PHP] (w/o *) around your code.
    you should also use indents inside of blocks ({ }) since it'll make your code alot easier to read.

    your while loops aren't wrong, but i wouldn't recommend using them.
    PHP Code:
    $num 0;
    while(
    $num $Admin[UploadNum]) {
    $num++;

    should be replaced with
    PHP Code:
    for($num=0;$num<$Admin[UploadNum];$num++) {

    it'd also look a lot cleaner if you replaced
    $picture = "fileup$num"."_name"; (and similar stuff) with $picture = "fileup". $num ."_name";

    as for removing the password check remove this codepiece:
    PHP Code:
     if($ADMIN[RequirePass] == "Yes") {
    if($password != "$ADMIN[Password]") {
    ?>
    <P align="center">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="0" CELLPADDING="0">
    <TR>
    <TD WIDTH="100%">
    <TABLE WIDTH="450" BORDER="0" CELLSPACING="1" CELLPADDING="2">
    <TR>
    <TD COLSPAN="2">
    <font color="#FF4400"><b>Invalid Password...</b></font>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </P>
    <?php
    exit();
    }
    }
    renaming $ADMIN[directory] is very easy..
    do a replace with your editor enter $ADMIN[directory] as search pattern and $files as replacement.

    last but not least:
    PHP Code:
    <FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $filename ?>?action=membersarea_uploadfiles" METHOD="POST">
    maybe i'm blind, but where exactly did you set $filename?
    Last edited by Son-Goku; Tue 1st Jul '03, 9:48am.

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    X