Jump to content

Cant add anything to this page, otherwise it will be blank...


KC8Alen

Recommended Posts

hi guys,

I'm pretty newb to php, so I was wondering if anyone could help me out with the Page below,.. I've wasted 12 hours about this thing and I cant help myself out. Anyways the problem is it looks like I can't add anything to this page, otherwise the whole page wont function, i know i haven't add a echo yet to notify the user about the successful uploaded. Also, I can't seem to get the mkdir to work with the $_POST['X'], So i thought I'd use the date(); to create a folder.

 

I'm also googled a lot about move file and temporary file etc, but i cant seem to get it work with the script below.

I've also tried to check this page out to make the server rename the file incase it will overwrite a existing file, but i get the same result, a blank page... and it wont even create the folder with date http://php.about.com/od/advancedphp/ss/rename_upload.htm

 

I hope someone can help me out,

 

Thanks alot!!

I really appreciate it.

 

 

<?php

// Start function \\
function handleError()
{
    trigger_error('MY ERROR');
} 
// detect slash/backslash nomenclature dirname 
$path = dirname( __FILE__ ); 
$slash = '/'; 

(stristr( $path, $slash )) ? '' : $slash = '\\'; 
define( 'BASE_DIR', $path . $slash ); 

$folder = date("d.m.y");         // folder name
//$dirPath = BASE_DIR . $folder;
$dirPath = BASE_DIR . $folder;  // folder path

$rs = @mkdir( $dirPath, 0777 ); 
@handleError();
// end of function \\

  $allowedExtensions = array("txt","xls","csv","doc","docx","rtf","ppt","pdf","jpg","jpeg","gif","png","bmp"); 
  foreach ($_FILES ++ as $file) 
  { 
    if ($file['tmp_name'] > '') 
{ 
      if (!in_array(end(explode(".", 
            strtolower($file['name']))), 
            $allowedExtensions)) 
  { 
       die($file['name'].' is niet een bruikbaar bestand voor als factuur!<br/><br/><br/> Ga terug naar de '. 
        '<a href="javascript:history.go(-1);">'. 
        'vorige</a> pagina. <br/><br/><br/> Alleen de bestanden met de volgende extensies zijn toegestaan: <br/><br/>| ".csv" | ".xls" | ".txt" | ".doc" | ".docx" | ".rtf" | ".ppt" | ".pdf" | ".jpg" | ".jpeg" | ".gif" | ".png" | ".bmp" |');

      }
    }
  }
  
?>

 

(This is the code I was trying to add in my page to randomize the upload file name.)

     //This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
    $ran = rand () ;

    //This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
    $ran2 = $ran.".";

    //This assigns the subdirectory you want to save into... make sure it exists!
    $target = "images/";

    //This combines the directory, the random file name, and the extension
    $target = $target . $ran2.$ext; 

 

Link to comment
Share on other sites

I changed the name to:

 

<input name="userfile[<? echo $x;?>]"

 

so i just put [] between the php echo

 

but it now seems not to block any not allowed extensions.

 

This is how my second page looks like (the first page is just a form and works fine so i just show the second page and third page where the problem occurs )

 

page 2:

<html>
<head><title>Uploadform</title>
</head>
<body><?
include 'conexxion.php';

// formulier POST variabelen ophalen

$bnaam = $_POST['bnaam'];
$kvk = $_POST['kvk'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$contpers = $_POST['contpers'];
$adres = $_POST['adres'];
$jaar = $_POST['jaar'];
$pcode = $_POST['pcode'];
$plaats = $_POST['plaats'];
$datum = date("Y-m-d");
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);
$abadvies = $_POST['adminadvies'];
$stat = $_POST['stat'];
$wie1 = $_POST['wie_1'];
$kost1 = $_POST['kost_1'];
$wie2 = $_POST['wie_2'];
$kost2 = $_POST['kost_2'];
$wie3 = $_POST['wie_3'];
$kost3 = $_POST['kost_3'];
$wie4 = $_POST['wie_4'];
$kost4 = $_POST['kost_4'];
$wie5 = $_POST['wie_5'];
$kost5 = $_POST['kost_5'];

// unix timestamp om het tijdstip de van de boodschap op te slaan.

$time= time();

// sql insert die je in de database gaat doen

$sql ="INSERT INTO Survey_1(Bedrijfsnaam, Kvknr, Telefoonnummer, Emailadres, Contactpersoon, Adres, Jaar_van_oprichting, Postcode, Plaats, Datum, IP, Admin_en_Belastingadvies, Huidige_situatie, Wie_doet_dit_1, Wat_kost_dit_1, Wie_doet_dit_2, Wat_kost_dit_2, Wie_doet_dit_3, Wat_kost_dit_3, Wie_doet_dit_4, Wat_kost_dit_4, Wie_doet_dit_5, Wat_kost_dit_5)
VALUES ('".$bnaam."', '".$kvk."', '".$tel."', '".$email."', '".$contpers."', '".$adres."', '".$jaar."', '".$pcode."', '".$plaats."', '".$datum."', '".$ip."', '".$abadvies."', '".$stat."', '".$wie1."', '".$kost1."', '".$wie2."', '".$kost2."', '".$wie3."', '".$kost3."', '".$wie4."', '".$kost4."', '".$wie5."', '".$kost5."')";

//uitvoeren van de query :

if (!($temp = mysql_query($sql,$connection)))
showerror();
else
echo("<B>Uw bedrijf met de naam ' " . $_POST['bnaam'] . " ' is opgeslagen in de database</B><br/><br/>Kies een bestand / factuur dat u wilt uploaden en druk vervolgens op volgende<P>")

?>

<form name="form1" enctype="multipart/form-data" method="post" action="766.php">
  <p>
  <?
  // start of dynamic form
  $uploadNeed = $_POST['uploadNeed'];
  for($x=0;$x<$uploadNeed;$x++){
  ?>
<!--     <P><br/><? echo $x;?><input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>"> -->
    <P><br/><? echo $x;?><input name="userfile[<? echo $x;?>]" type="file" id="userfile[<? echo $x;?>]">
  </p>
  <p>
    <?
  // end of for loop
  }
  ?>
  
    <br />
  </p>
  <p>- Indien u op de vorige pagina " 0 " heeft ingetoetst, druk dan gewoon op de onderste knop om verder te gaan.<br />
    - Als u op de vorige pagina teveel heeft ingevoerd voor het uploaden negeer de rest van de uploads, u hoeft niet alle vakken te gebruiken.
  </p>

<input style="display: none;" name="bnaam"id="bnaam" rows="1" type="hidden"><?PHP $_POST['bnaam']; ?></input><br>
  <p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
    <input type="submit" name="Submit" value="Bestand versturen">
    <br />
    <br />
    * Mocht u een fout melding krijgen over email of dergelijke, ga dan terug naar de <a href="javascript:history.go(-1);">vorige</a> pagina en gebruik een andere e-mail adres, <br />
  het is mogelijk dat deze al in gebruik is. </p>
</form>
</body>
</html>

 

Page 3:

<?php

// Start function \\
function handleError()
{
    trigger_error('MY ERROR');
} 
// detect slash/backslash nomenclature dirname 
$path = dirname( __FILE__ ); 
$slash = '/'; 

(stristr( $path, $slash )) ? '' : $slash = '\\'; 
define( 'BASE_DIR', $path . $slash ); 

$folder = date("d.m.y");         // folder name
//$dirPath = BASE_DIR . $folder;
$dirPath = BASE_DIR . $folder;  // folder path

$rs = @mkdir( $dirPath, 0777 ); 
@handleError();
// end of function \\

  $allowedExtensions = array("txt","xls","csv","doc","docx","rtf","ppt","pdf","jpg","jpeg","gif","png","bmp"); 
  foreach ($_FILES['userfile'] as $file) 
  { 
    if ($file['tmp_name'] > '') 
{ 
      if (!in_array(end(explode(".", 
            strtolower($file['name']))), 
            $allowedExtensions)) 
  { 
       die($file['name'].' is niet een bruikbaar bestand voor als factuur!<br/><br/><br/> Ga terug naar de '. 
        '<a href="javascript:history.go(-1);">'. 
        'vorige</a> pagina. <br/><br/><br/> Alleen de bestanden met de volgende extensies zijn toegestaan: <br/><br/>| ".csv" | ".xls" | ".txt" | ".doc" | ".docx" | ".rtf" | ".ppt" | ".pdf" | ".jpg" | ".jpeg" | ".gif" | ".png" | ".bmp" |');

      }
    }
  }
  move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
  "/uploads/" . $_FILES["fileToUpload"]["name"]);
?>

 

This thing is rlly getting me crazy, any help would really be appreciated.

Link to comment
Share on other sites

I re-wrote page 3 have a look

 

function my_form_add_error($error, $form_name = 'default') {
    $_SESSION[$form_name][] = $error;
}

function my_form_get_errors($form_name = 'default') {
    return isset($_SESSION[$form_name]) ? $_SESSION[$form_name] : array();
}

function my_error_handler($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()) {
    if ($errno === E_USER_ERROR) {
        echo "#$errno: $errstr ($errfile:$errline)";
        exit(0);
    }
}
set_error_handler('my_error_handler');

$cwd = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$directory_name = date('d.m.y');
$directory_path = $cwd . $directory_name . DIRECTORY_SEPARATOR;
if (!is_dir($directory_path) && !@mkdir($directory_path, 0644)) {
    trigger_error("Kon de map $directory_name ($directory_path) niet maken", E_USER_ERROR);
}

if (isset($_FILES['userfile'])) {
    $allowed_ext = array();
    foreach ($_FILES['userfile']['error'] as $key => $value) {
        $name = $_FILES['userfile']['name'][$key];
        if ($key === UPLOAD_ERR_OK) {
            $tmp_name = $_FILES['userfile']['tmp_name'][$key];

            $ext = pathinfo($name, PATHINFO_EXTENSION);
            if (!in_array($ext, $allowed_ext)) {
                my_form_add_error("Ongeldige extensie voor bestand $name (" . implode(', ', $allowed_ext) . ')');
            }

            if (!move_uploaded_file($tmp_name, $directory_path . $name)) {
                if (chmod($directory_path, 0644)) { // probeer te chmodden naar 0644
                    if (!move_uploaded_file($temp_name, $directory_path . $name)) {
                        my_form_add_error("Kon het bestand $name niet uploaden");
                    }
                }
            }
        }

        else {
            my_form_add_error("Het bestand $name is niet of slechts gedeeltelijk geüpload, probeer opnieuw");
        }
    }
}

Link to comment
Share on other sites

Page 2:

 

It's to verify this page first as the variable names now match the value of name=".." make sure they are named correctly throughout the script

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Uploadform</title>
</head>
<body>

<?php include 'conexxion.php';

function clean($value) {
    $value = strip_tags($value);
    $value = htmlentities($value);
    $temp = @mysql_real_escape_string($value)
        ? $value = $temp
        : $value = addslashes($value);
    return $value;
}

$_POST = array_map('clean', $_POST);
extract($_POST);

$request_time = isset($_SERVER['REQUEST_TIME'])
    ? $_SERVER['REQUEST_TIME']
    : time();

// sql insert die je in de database gaat doen
$sql = 'INSERT INTO Survey_1 (Bedrijfsnaam, Kvknr, Telefoonnummer, Emailadres, Contactpersoon, Adres,'
     . 'Jaar_van_oprichting, Postcode, Plaats, Datum, IP, Admin_en_Belastingadvies, Huidige_situatie, Wie_doet_dit_1,'
     . 'Wat_kost_dit_1, Wie_doet_dit_2, Wat_kost_dit_2, Wie_doet_dit_3, Wat_kost_dit_3, Wie_doet_dit_4, Wat_kost_dit_4,'
     . 'Wie_doet_dit_5, Wat_kost_dit_5) VALUES ('
     . "'$bnaam','$kvk','$tel','$email,'$contpers','$adres','$jaar','$pcode','$plaats','$datum','$ip','$abadvies',
        '$stat','$wie1','$kost1','$wie2','$kost2','$wie3','$kost3','$wie4','$kost4','$wie5','$kost5')";

//uitvoeren van de query :
$result = mysql_query($sql);
if ($result) {
    echo "<b>Het bedrijf $bnaam is met success opgeslagen.</b>",
         '<p>Kies een bestand/factuur dat u wilt uploaden en druk vervolgens op volgende.</p>';
}

?>

<form name="form1" enctype="multipart/form-data" method="POST" action="766.php">
    <input name="bnaam" type="hidden" value="<?php echo $bnaam; ?>">
    <input name="uploadNeed" type="hidden" value="<?php echo $uploadNeed;?>">

    <?php

    // start of dynamic form
    if (isset($_POST['uploadNeed'])) {
        $uploadNeed = intval($_POST['uploadNeed']);
        for ($i = 0; $i < $uploadNeed; ++$i) {
            echo '<div><label>Kies een bestand: <input type="file" name="userfile[]"></label></div>';
        }
    }

    ?>

    <p>- Indien u op de vorige pagina " 0 " heeft ingetoetst,
        druk dan gewoon op de onderste knop om verder te gaan.</p>

    <p>- Als u op de vorige pagina teveel heeft ingevoerd voor het uploaden negeer de rest van de uploads,
        u hoeft niet alle vakken te gebruiken.</p>

    <input type="submit" name="Submit" value="Bestand versturen">

    <p>* Mocht u een fout melding krijgen over email of dergelijke,
        ga dan terug naar de <a href="javascript:history.go(-1);">vorige</a> pagina en gebruik een andere e-mail adres,
        het is mogelijk dat deze al in gebruik is. </p>
</form>
</body>
</html>

Link to comment
Share on other sites

hi ignace

 

I've looked @ page 2 but I dont see anything about retrieve POST, and it doesnt save to my MYSQL also.

 

also, on the page 1 (form) I have an textbox to let the user type in how many uploads he/she wants to upload but, whenever i use your page two to make the page one send the form to it, it doesnt even show 1 upload box.

 

It doesnt matter what number you fill in.

 

This is the code of my number box, actually i copied from somewhere on the internet and made a few changes, but it worked, just the move file part.... anyways here is the code of the form for the number of uploadbox the user wants in the next coming page to show up:

 

 

<form name="nxt" action="srvy1uload-.php" method="POST" onsubmit="return validator(this);">

    <input name="uploadNeed" type="text" id="uploadNeed" size="2" maxlength="2" />

       ( U mag maximaal 20 invullen )

  <table width="803">

  <td width="90%">--> Klik vervolgens op volgende om verder te gaan.</td>

        <input type="hidden" id="action" name="action" value="submitform" />

  <td width="10%"><input type="submit" name="verzenden" id="verzenden" value="Volgende"/></td>

  </table>

</form>

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.