Jump to content

PHP UPLOAD FORM


scoobs001

Recommended Posts

Hiya people, I am new on here, and new to PHP.

 

I am using a script that i have downloaded and have modified it to get it working in ht eway i want. (almost)

 

But i am stuck on a few things,

 

* The script does not work in Internet Explorer, This might be to do with the file permissions that i have allowed??? it works in firefox fine,

 

* I have managed to get most things working, I am wanting to add more that one upload box, so people can upload more as one image, but if they only choose to upload 1, the second "blank" box does not require a file in it. I have been reading up on the "For Each" command, but i tried a few things with no joy.

 

* Also, If there is anyhting else you would recomend, it would be great.

 

Uploaded images will only be pictures, so i wasn't too fussed about a status bar, especially when i seen all the extra code i would have to work out ???

 

Any help would be great. This is the first time i have used PHP, It is great! :)

 

Anyways, Here is my code, First is the form on the webpage(HTML) and the second is the PHP server side script. Server  is Linux if that helps)

<form method="post" action="output.php" enctype="multipart/form-data">

          <div align="right">

            <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Name

              <input name="Name" type="text" id="Name" size="30" />

              <br />

              </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br />

              Email Address

              <input name="email" type="text" id="email2" size="30" />

              <br />

              <br />

              Postal Address (if Req)

              <textarea name="Address" cols="25" rows="4" wrap="VIRTUAL" id="Address"></textarea>

              <br />

              <br />

              Detailed instructions for picture

              <textarea name="Instructions" cols="45" rows="5" wrap="VIRTUAL" id="Instructions"></textarea>

              <br />

              <br />

              Upload1

 

              <input name="upload" type="file" size="30" />

  <input name="upload2" type="file" size="30" />

 

              <br />

              <br />

              </font>

              <input name="submit" type="submit" value="Submit" />

              <br />

              <font color="#FF0000">Please note : It may take several minutes

              to upload the file, you will be automaticly forwarded once the upload

              is complete.</font> </p>

            </div>

        </form>

 

  // Receiving variables

@$Name = addslashes($_POST['Name']);

@$address = addslashes($_POST['Address']);

@$instructions = addslashes($_POST['Instructions']);

@$email = addslashes($_POST['email']);

@$upload_Name = $_FILES['upload']['name'];

@$upload_Size = $_FILES['upload']['size'];

@$upload_Temp = $_FILES['upload']['tmp_name'];

@$upload_Mime_Type = $_FILES['upload']['type'];

 

 

 

function RecursiveMkdir($path)

{

  if (!file_exists($path))

  {

      RecursiveMkdir(dirname($path));

      mkdir($path, 0777);

    }

  }

 

 

// Validation

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))

{

die("<p align='center'><font face='Arial' size='5' color='#FF0000'>Please enter a valid email</font></p>");

}

 

if( $upload_Size == 0)

{

die("<p align='center'><font face='Arial' size='5' color='#FF0000'>Please enter a valid upload</font></p>");

}

if( $upload_Size >100000000000000)

{

//delete file

unlink($upload_Temp);

die("<p align='center'><font face='Arial' size='5' color='#FF0000'>Please enter a valid upload</font></p>");

}

if(  $upload_Mime_Type != "image/jpeg" AND $upload_Mime_Type != "image/gif")

{

unlink($upload_Temp);

die("<p align='center'><font face='Arial' size='5' color='#FF0000'>Please enter a valid upload</font></p>");

}

$uploadFile = "uploads/".$upload_Name ;

if (!is_dir(dirname($uploadFile)))

  {

    @RecursiveMkdir(dirname($uploadFile));

  }

else

  {

  @chmod(dirname($uploadFile), 0777);

  }

@move_uploaded_file( $upload_Temp , $uploadFile);

chmod($uploadFile, 0644);

$upload_URL = "http://www.digicars.co.uk/uploads/".$upload_Name ;

 

// Change this to your email address

//Sending Email to form owner

# Email to Owner

$pfw_header = "From: $email";

$pfw_subject = "Image Submitted";

$pfw_email_to = "[email protected]";

$pfw_message = "Name: $Name\n"

. "Address: $address\n"

. "Instructions: $instructions\n"

. "E-mail: $email\n"

. "Image upload Path: $upload_URL\n";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

// Change this to your email address

//Sending auto respond Email to user

# Email to Owner

$pfw_header = "From: [email protected]";

$pfw_subject = "Confirmation";

$pfw_email_to = "$email";

$pfw_message = "Name: $Name\n"

. "Address: $address\n"

. "Instructions: $instructions\n"

. "E-mail: $email\n"

. "Image uploaded: $upload_URL\n"

. "\n"

. "\n"

. "\n"

. "Please confirm the above details are correct - If they are not, then please send me an email and we can correct them\n"

. "\n"

. "\n"

. "\n"

 

. "DigiCars.co.uk\n"

. "[email protected]\n"

. "\n"

. "\n"

. "--------------------------------------------------------------------------------------------------------\n"

. "\n"

. "\n";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

 

// Change this to your new file name

//saving record in a text file - Make Sure You Rename the data.csv to something like mydata.csv and chmod to 666

$pfw_file_name = "mydata.csv";

$pfw_first_raw = "Name,address,instructions,email,upload\r\n";

$pfw_values = "$Name,$Address,$instructions,$email,$upload_Name\r\n";

$pfw_is_first_row = false;

if(!file_exists($pfw_file_name))

{

$pfw_is_first_row = true ;

}

if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {

die("Cannot open file ($pfw_file_name)");

exit;

}

if ($pfw_is_first_row)

{

  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

  }

}

if (fwrite($pfw_handle, $pfw_values) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

}

fclose($pfw_handle);

include("paypal.htm");

?>

Link to comment
https://forums.phpfreaks.com/topic/50022-php-upload-form/
Share on other sites

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.