View Single Post
  #41  
Old 12-12-2006, 05:32 AM
mrdaytrade mrdaytrade is offline
Private
 
Join Date: Dec 2006
Posts: 2
Default How To Prevent Files From Being Overwritten

I know in frontpage you can set folder properties so file uploads can not overwrite existing files. If a uploaded did this the form would redirect them to an error page stating to rename the file and try again.

I am trying to get away from using frontpage, so I used your code from above to modify my form. I had to combine some of the validation to get it to work... I kept getting an Parse error: parse error, unexpected $ in the last line.

However, I'm affraid that some people may have the same file name when uploading photos... Is their something I can add to the script to prevent overwriting and a possible error page telling them how to correct the problem. Or even a number being automaticly added to the file name.

Is it possible to send the information to a file on the server too? Thanks for the help in advance. I'll send you a digital music coupon.

Here is my form:
http://www.capitalareaapartments.com/uploadform.htm

Code:

<?php
// Receiving variables
@$email = addslashes($_POST['email']);
@$upload1_Name = $_FILES['upload1']['name'];
@$upload1_Size = $_FILES['upload1']['size'];
@$upload1_Temp = $_FILES['upload1']['tmp_name'];
@$upload2_Name = $_FILES['upload2']['name'];
@$upload2_Size = $_FILES['upload2']['size'];
@$upload2_Temp = $_FILES['upload2']['tmp_name'];
// Validation for max file size
if ($upload1_Size>0)
{
if( $upload1_Size >1000000)
{
//delete file
unlink($upload1_Temp);
header("Location: error.html");
exit;
}
$uploadFile = "uploads/".$upload1_Name ;
@move_uploaded_file( $upload1_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload1_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload1_Name">http://www.capitalareaapartments.com/uploads/".$upload1_Name ;
}
if ($upload2_Size>0)
{
if( $upload2_Size >1000000)
{
//delete file
unlink($upload2_Temp);
header("Location: error.html");
exit;
}
$uploadFile = "uploads/".$upload2_Name ;
@move_uploaded_file( $upload2_Temp , $uploadFile);
chmod($uploadFile, 0644);
$upload2_URL = "<A href="http://www.capitalareaapartments.com/uploads/".$upload2_Name">http://www.capitalareaapartments.com/uploads/".$upload2_Name ;
}
//Sending Email to form owner
$mailto = "sales@capitalareaapartments.com";
$mailsubj = "Ad Listing";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form :\n";
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
if ($key!="submit")
{
$mailbody .= "$key : $val\n";
}
}
$mailbody .= "upload1: $upload1_URL\n";
$mailbody .= "upload2: $upload2_URL\n";
mail($mailto, $mailsubj, $mailbody, $mailhead);
header("Location: orderconfirm.htm");
?>


Thank you for the code, it was the only site that explained it perfectly!!!
-Tony
Reply With Quote