PHP form with upload,


Can somebody help me sovle this problem.

I have made a phpform (using a phpgenerator) with upload funktion.
The thing it should do is to make the felt: name, email, band and besked as requiered felts and the upload optional. But the thing it does is that it only works where a file is upload other wise it gives me the error msg down in the buttom.

Can anyone help me??

Thanks, Mads


<?php include(""); $errors=0; $error="The following errors occured while processing your form input.
    "; pt_register('POST','Name'); pt_register('POST','Email'); pt_register('POST','Band'); pt_register('POST','Besked'); $Besked=preg_replace("/(1512)|(15)|(12)/"," 
    ", $Besked);$upload=$HTTP_POST_FILES['upload']; if($Name=="" || $Email=="" || $Band=="" || $Besked=="" ){ $errors=1; $error.="
  • Du mangle at udfylde nogle felter som er n?dvendige. Pr?v igen."; } if($HTTP_POST_FILES['upload']['tmp_name']==""){ } else if(!is_uploaded_file($HTTP_POST_FILES['upload']['tmp_name'])){ $error.="
  • The file, ".$HTTP_POST_FILES['upload']['name'].", was not uploaded!"; $errors=1; } if(!eregi("^[a-z0-9]+([_\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([.-][a-z0-9]+)*)+"."\.[a-z]{2,}"."$",$Email)){ $error.="
  • Ugyldig email adressse"; $errors=1; } if($errors==1) echo $error; else{ $image_part = date("h_i_s")."_".$HTTP_POST_FILES['upload']['name']; $image_list[4] = $image_part; copy($HTTP_POST_FILES['upload']['tmp_name'], "files/".$image_part); $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/")); $message="Name: ".$Name." Email: ".$Email." Band: ".$Band." Besked: ".$Besked." upload: ".$where_form_is."files/".$image_list[4]." "; $message = stripslashes($message); mail("","Materiale Bestilling",$message,"From: Oldnick"); header("Refresh: 0;url="); ?><?php


    ERROS: I have masked the ulr.

    Warning: Unable to access in /customers/ on line 27

    Warning: Cannot add header information - headers already sent by (output started at /customers/ in /customers/ on line 38


I found out that i get a mail, when i fill out the form exept the upload feld, but it gives me the error. But if I type a letter in the upload feld it redirects me the right page and it works.

Any Ideas??

Thansk Mads


To get around this you need to fully understand the PHP header() function.

There cannot be any output sent to the browser BEFORE the header() function is called. This includes whitespace.

For more information check this out:



I pretty much a newbi at this soo I realy dont understad the thing a the linked page, can you show me what part of the code there is wrong??

The thing that I dont understand i that I get the mail even though the error occur. And if i fill out all the felts (name, email, band, besked and upload) it works.