shadiadiph Posted February 19, 2009 Share Posted February 19, 2009 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 https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/ Share on other sites More sharing options...
peddel Posted February 19, 2009 Share Posted February 19, 2009 plz post both files completely so we can see how the transfer of variables is programmed Link to comment https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765964 Share on other sites More sharing options...
Cal Posted February 19, 2009 Share Posted February 19, 2009 peddel is right. it's no use just posting part of the script, post all the parts that interact with it because the problem could be in the other code. Link to comment https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765968 Share on other sites More sharing options...
shadiadiph Posted February 19, 2009 Author Share Posted February 19, 2009 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 https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765972 Share on other sites More sharing options...
peddel Posted February 19, 2009 Share Posted February 19, 2009 again post ur complete files, the first piece of code is not the complete code ... i cannot start guessing how it all works ... Link to comment https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765983 Share on other sites More sharing options...
PFMaBiSmAd Posted February 19, 2009 Share Posted February 19, 2009 $_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 https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765986 Share on other sites More sharing options...
shadiadiph Posted February 19, 2009 Author Share Posted February 19, 2009 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 = '[email protected]'; $subject = "New Account"; $boundary = '==Multipart_Boundary_x' .md5(time()). 'x'; // headers $headers .= "From: Website <[email protected]>\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 https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-765991 Share on other sites More sharing options...
shadiadiph Posted February 19, 2009 Author Share Posted February 19, 2009 mm been tring out that error one can't get it working because it is being passed as an array Link to comment https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-766005 Share on other sites More sharing options...
shadiadiph Posted February 19, 2009 Author Share Posted February 19, 2009 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 https://forums.phpfreaks.com/topic/145887-file-attachment-true-or-false-problem/#findComment-766012 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.