Jump to content

file attachment true or false problem


shadiadiph

Recommended Posts

on the page before this one the user has the opportunity to upload some files problem is when this submits everytime with files attached or not attached it returns the value of false I tried it with

$fileatt = $_FILES['fileatt']; gives the same result any ideas??

 

$fileatt	            =     ($_POST["fileatt"]);

if ($fileatt==true)
{
$status ="Attached";
}
if ($fileatt==false)
{
$status ="Upload Later";
}

Link to comment
Share on other sites

ok here is the form code it posts and my submit form works fine uploads the files if they exist etc i just need to make a clause for if they have been uploaded or not not an error message

 

<form name="iapply3" method="post" action="../submit/isubmit.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<table class="form">
<tr><td colspan="2" class="head">PHOTO 1</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
<tr><td colspan="2" class="head">PHOTO 2</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
<tr><td colspan="2" class="submit" ><input name="submit" type="submit" value="Submit" /></td></tr>
<tr><td colspan="2" class="submit"><input name="reset" type="reset" value="Reset" /></td></tr>
<tr><td class="head"> </td><td class="head"> </td></tr>
</table>
</form>

Link to comment
Share on other sites

$_FILES['fileatt'] will be set even if no file is uploaded. You would need to check the ['error'] element for a value of 4 to detect that no file was uploaded - http://us2.php.net/manual/en/features.file-upload.errors.php

 

You should be checking the ['error'] element anyway to detect errors before your code makes use of any of the uploaded file information. An error value of zero would mean a file was successfully uploaded.

 

If you use the following diagnostic code to see what is present, it should give you an idea what your code needs -

 

echo "<pre>";
print_r($_FILES);
echo "</pre>";

Link to comment
Share on other sites

i prety much gave you everything before that was relevant this is a user submit page and is 400 lines long i just butchered it down and removed the irrelevant bits alot of post data and sql inserts etc the submit page works fine 100% send the files as attachments saves the files on the server fine creates the user directory to save to fine the only problem is the $status to state if a file has been attached or not :( probably something simple i have tried is_file etc don't know what to do any help is appreciated thanks

 

form

<form name="iapply3" method="post" action="../submit/isubmit.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<table class="form">
<tr><td colspan="2" class="head">PHOTO 1</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
<tr><td colspan="2" class="head">PHOTO 2</td></tr>
<tr><td colspan="2" class="name"><input type="file" name="fileatt[]" /></td></tr>
<tr><td colspan="2" class="submit" ><input name="submit" type="submit" value="Submit" /></td></tr>
<tr><td colspan="2" class="submit"><input name="reset" type="reset" value="Reset" /></td></tr>
<tr><td class="head"> </td><td class="head"> </td></tr>
</table>
</form>

 

 

relevant submit code

<? 
session_start();
error_reporting(apa);
error_reporting(7);
include("../secure/global/connection.php");
ini_set ('upload_max_filesize','10M');


$username		      =	($_POST["username"]);
$email		      =	($_POST["email"]);
$ipaddress	            =     ($_POST["ipaddress"]);

if (is_uploaded_file($_FILES['fileatt']['size'])) {

$status ="Attached";
}
else
{
$status ="Upload Later";
}

if($username=="")
{
        header("Location: ../accounts/ionline.php");
        exit;
}

if (file_exists("../secure/webadmin/clients/$username"))
{
}
else
{
mkdir("../secure/webadmin/clients/$username", 0700);
}


        $to = 'info@website.com';
        $subject = "New Account";
        $boundary = '==Multipart_Boundary_x' .md5(time()). 'x';
        // headers
        $headers .= "From: Website <noreply@website.com>\n";  
        $headers .= "MIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n\n";
        // message
        $message = "--{$boundary}\n";
        $message .= "Content-Type: text/html; charset=iso-8859-1\n";
        $message .= "Content-Transfer-Encoding: 7bit\n\n";
        $message .= "<html>
<head>
<title>HTML message</title>

</head>
<body>
<table>
<tr><td align='left'><img src='http://www.website.com/pix/logo.gif'></td></tr>
<tr><td> </td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>
<b>Details:</b><br /> 
IP Address: $ipaddress<br />
Attachments: $status<br />
</td></tr>
<tr><td><font style='font-size: 13px' style='font-family: Tahoma, Arial'>
<b>Contact Details:</b><br /> 
Userame: $username <br />
Email: $email <br />
<tr><td> </td></tr>
<tr><td><font style='font-size: 11px' style='color: #336699' style='font-family: Tahoma, Arial'>This message, and any attachments, is intended only for the use of the individual or entity to which it is addressed, and may contain confidential, proprietary and/or privileged information that is exempt from disclosure under applicable law which is not waived or lost by any transmission failure. 
If the reader of this message is not the intended recipient or its employee, or agent responsible for delivering the message to the intended recipient, you are hereby notified that any use, dissemination, distribution or copying of this communication and any attachments hereto is strictly prohibited. 
If you have received this communication in error, please destroy this message. 
Any views expressed in this message are those of the individual sender, except where the message states otherwise and the sender is authorised to state them to be the views of another person or entity. </font></td></tr>
</table>

</body>
</html>";




foreach ($_FILES["fileatt"]["error"] as $key => $error) { 
        if ($error == UPLOAD_ERR_OK) { 
$fileatt = $_FILES['fileatt']['tmp_name'][$key];
$fileatt_type = $_FILES['fileatt']['type'][$key];
$fileatt_name = $_FILES['fileatt']['name'][$key]; 

       
        // attachment

        $fp = fopen($fileatt, 'rb');
        $data = fread($fp, filesize($fileatt));
        fclose($fp);

        $data = chunk_split(base64_encode($data));
        $message .= "\n\n";
        $message .= "--{$boundary}\n";
        $message .= "Content-Type: application/$fileatt_type; name=\"$fileatt_name\"\n";
        $message .= "Content-Transfer-Encoding: base64\n\n";
        $message .= "$data\n\n";

move_uploaded_file($fileatt, "./../secure/webadmin/clients/$username/$fileatt_name"); 
       
    } 
}


        mail($to, $subject, $message, $headers);





?>

Link to comment
Share on other sites

this half works if no files are uploaded its fine Upload Later if two files are uploaded Attached is returned the problem is where only one file is uploaded it depends on which upload box it is uploaded in as it always returns the last possible result

 

foreach ($_FILES["fileatt"]["error"] as $key => $error) { 
        if ($error == UPLOAD_ERR_OK) { 
$status = "Attached";
}
        if ($error == UPLOAD_ERR_NO_FILE) { 
$status = "Upload Later";
}
}

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.