
dmikester1
Members-
Posts
107 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
dmikester1's Achievements

Member (2/5)
0
Reputation
-
accessing a value in a multidimensional associative array
dmikester1 replied to dmikester1's topic in PHP Coding Help
Thank you. I changed the way I was inserting in the array. I knew there had to be an easier way than what I was doing, but was having a brain fart or something. Thanks! -
I'm having some troubles with this one. I set up my array like so: $POs[] = array( $jobID=>array( 'FSME' => $matTotal, 'FSMC' => $matTotal, 'FSDE' => $draftingTotal, ... And say $jobID is equal to 312. Now I am trying to access one of those values. I tried: $POs[$jobID]['FSME'] with $jobID being 312. Then I get "Notice: Undefined offset: 312 in..." Any ideas how I can access this variable? Thanks Mike
-
I can't figure out how to remove a specific item from my array by key. Array: $uncachedSites = array(2=>'site 1', 3=>'site 2', 4=>'site 3', 5=>'site 4'); So I'm running through a loop with $i starting at 2 and going up to 5. If I say unset($uncachedSites[$i], the first time around I'm thinking it will remove 'site 3' instead of 'site 1' like I want it to. But I can't figure out how to remove the first one without just saying unset($uncachedSites[0]) Thanks Mike
-
Well, the second argument passed to array_map needs to be an array and that long id number is obviously not an array.
-
It appears that argument 2 of array_map is not an array. When you do this: "print_r ($_POST['need_delete']);", what do you get?
-
setting several selects to a specific position
dmikester1 replied to jaco's topic in PHP Coding Help
I assume you are setting $prog2_menu and $prog1_menu from the GET variables earlier in your PHP code? You really need to learn to use some CSS. This is UGLY! echo " Ascending bass line"; -
Trying to get file to attach to email message from upload form
dmikester1 replied to wolfsta's topic in PHP Coding Help
I just had to do this earlier today. This is what worked for me. This works for multiple files. Mike if(isset($_FILES['uploadFiles']['name'])) { foreach ($_FILES['uploadFiles']['name'] as $i => $name) { if ($_FILES['uploadFiles']['error'][$i] == 4) { continue; } if ($_FILES['uploadFiles']['error'][$i] == 0) { if ($_FILES['uploadFiles']['size'][$i] > 99439443) { $messages[] = "$name exceeded file limit."; continue; } if(move_uploaded_file($_FILES['uploadFiles']['tmp_name'][$i], "uploads/$name")) { $uploaded++; $files[] = "uploads/$name"; } else { echo "Could not upload $name to be attached!<br />"; } } } //$files = $_FILES['uploadFiles']['tmp_name']; } echo "$uploaded receipt"; if($uploaded != 1) { echo "s"; } echo " uploaded."; foreach ($messages as $error) { echo $error; } // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $eol = PHP_EOL; $headers = "From: ".$to.$eol; $headers .= "Reply-To: ".$to.$eol; $subject = "Expense Report - Period Ending $reportDate"; $headers .= $eol."MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol; // no more headers after this, we start the body! // //$body = "--".$mime_boundary.$eol; //$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= "This is a multi-part message in MIME format.".$eol; // message $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= $message.$eol.$eol; if($uploaded > 0) { // if there are attachments add this line to the message, otherwise with no attachments this line will add an unwanted attachment //$body .= "--{$mime_boundary}\n"; } if(isset($_FILES['uploadFiles']['name'])) { // preparing attachments for($x=0;$x<count($files);$x++){ $file = fopen($files[$x],"rb"); $data = fread($file,filesize($files[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $name = $_FILES['uploadFiles']['name'][$x]; /*$body .= "–{$mime_boundary}\n"; $body .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; //$body .="--{$mime_boundary}--\n"; if ($x==count($files)-1) { //$message .="--{$mime_boundary}-\n"; } else{ //$message .="--{$mime_boundary}\n"; }*/ // attachment $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: application/octet-stream; name=\"".$name."\"".$eol; $body .= "Content-Transfer-Encoding: base64".$eol; $body .= "Content-Disposition: attachment".$eol.$eol; $body .= $data.$eol.$eol; } $body .= "--".$mime_boundary."--"; } // send $ok = @mail($to, $subject, $body, $headers); if ($ok) { echo "<p>Email sent to $to!</p>"; } else { echo "<p>Email could not be sent!</p>"; } } -
WHERE live = 1 AND title LIKE \"%$term%\" OR description LIKE \"%$term%\" What do you want here? WHERE (live = 1 AND title LIKE \"%$term%\") OR description LIKE \"%$term%\" - or - WHERE live = 1 AND (title LIKE \"%$term%\" OR description LIKE \"%$term%\") Notice the change in parens. Mike
-
I assume eventually there will be much more than 2 lines in the text file? Instead of writing to a text file, it would be much more robust and easier to sort by adding the entries to a mysql database.
-
Do you have some starting code to help us out? I don't think many people here are willing to write the whole thing for you.
-
Sounds like something you could do with javascript/jquery/ajax. I'm not sure if that is possible with just PHP though. Unless they select the first dropdown and hit a submit button, but that would be cumbersome for the user. Someone correct me if I am wrong. Mike
-
Emailing an uploaded file, file corrupted
dmikester1 replied to dmikester1's topic in PHP Coding Help
Heh, figured this one out on my own. Turns out for my situation, I had to do a "move_uploaded_file" to a folder in my web root for it to work. Maybe this isn't always the case, but it fixed my problem. I also had to move the last "$body .= "--".$mime_boundary."--";" outside of the for loop to get it to work with multiple files. Maybe this will help someone else out. -
Emailing an uploaded file, file corrupted
dmikester1 replied to dmikester1's topic in PHP Coding Help
Do I have to move the uploaded file to a permanent location or can I just use the 'tmp_name' to email it? -
I need some help with emailing an uploaded file. The file is always corrupted and just a few bytes, when it is normally a few KB. I would prefer not to use the PHP mailer class so I can learn myself how to do the coding. Thanks Mike Here is the relevant code: $uploaded = 0; $messages = array(); if(isset($_FILES['uploadFiles']['name'])) { foreach ($_FILES['uploadFiles']['name'] as $i => $name) { if ($_FILES['uploadFiles']['error'][$i] == 4) { continue; } if ($_FILES['uploadFiles']['error'][$i] == 0) { if ($_FILES['uploadFiles']['size'][$i] > 99439443) { $messages[] = "$name exceeded file limit."; continue; } $uploaded++; } } $files = $_FILES['uploadFiles']['tmp_name']; } echo "$uploaded receipt"; if($uploaded != 1) { echo "s"; } echo " uploaded."; foreach ($messages as $error) { echo $error; } // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $eol = PHP_EOL; $headers = "From: ".$to.$eol; $headers .= "Reply-To: ".$to.$eol; $subject = "Expense Report - Period Ending $reportDate"; $headers .= "MIME-Version: 1.0".$eol; $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol; // no more headers after this, we start the body! // //$body = "--".$mime_boundary.$eol; //$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= "This is a multi-part message in MIME format.".$eol; // message $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol; $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol; $body .= $message.$eol.$eol; if($uploaded > 0) { // if there are attachments add this line to the message, otherwise with no attachments this line will add an unwanted attachment //$message .= "--{$mime_boundary}\n"; } if(isset($_FILES['uploadFiles']['name'])) { // preparing attachments for($x=0;$x<count($files);$x++){ $file = fopen($files[$x],"rb"); $data = fread($file,filesize($files[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $name = $_FILES['uploadFiles']['name'][$x]; /*$body .= "–{$mime_boundary}\n"; $body .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; //$body .="--{$mime_boundary}--\n"; if ($x==count($files)-1) { //$message .="--{$mime_boundary}-\n"; } else{ //$message .="--{$mime_boundary}\n"; }*/ // attachment $body .= "--".$mime_boundary.$eol; $body .= "Content-Type: application/octet-stream; name=\"".$name."\"".$eol; $body .= "Content-Transfer-Encoding: base64".$eol; $body .= "Content-Disposition: attachment".$eol.$eol; $body .= $data.$eol.$eol; $body .= "--".$mime_boundary."--"; } } // send $ok = @mail($to, $subject, $body, $headers); if ($ok) { echo "<p>email sent to $to!</p>"; } else { echo "<p>email could not be sent!</p>"; } } ?>
-
I have a PHP script that does some work copying some files and parsing through the files. Then it creates an Excel file and sends it to the browser to download. So you user will see the standard popup asking to save or open the file. Well, I am using ob_flush to try and output text to the browser while it is working so the user knows something is happening. But whenever I add the ob_flush lines in, it just sends a bunch of garbage text to the browser instead of downloading the file. Anyone know a way around this? Thanks Mike