Jump to content

kevdoug

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kevdoug's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I've got this error handling script but I am unsure how to define the directory for the log here is the full path where I have the logfile.txt  C:/log/logfile.txt I have tried [color=red]define ('logfile', C:/log/logfile.txt(__FILE__) . '/logfile.txt');[/color] I have tried other ways but with no luck. and here is the full script. <?php // Location of the error log file define ([color=green]'logfile'[/color], dirname([color=purple]__FILE__[/color]) . [color=green]'/logfile.txt'[/color]); function handle_errors($errlevel, $errstr, $errfile='', $errline='', $errcontext='') {   $errstr = htmlentities($errstr);   $error = '[' . date('d/m/Y H:i:s') . '] '; switch ($errlevel) {   case E_USER_ERROR:   $error .= "ERROR: ";   echo 'Sorry, something unexpected happen, and it has been logged for further investigation. Please go back where you came from. Thank you for your understanding.';   $die = true;   break;   case E_USER_WARNING:   case E_WARNING:   $error .= "WARNING: ";   break;   case E_USER_NOTICE:   case E_NOTICE:   $error .= "NOTICE: ";   break;   default:   $error .= "UNKNOWN: ";   break;   }   $error .= " $errstr in line $errline of file $errfile\n";   // Log error   $f = fopen(logfile, 'a');   fwrite($f, $error);   fclose($f);   // Error -> stop script execution?   if (isset($die) AND $die == true) {           die();   } } echo set_error_handler('handle_errors'); // Throws a notice $a = $b; // Throws a warning: $f = fopen('bla'); // Throws a user notice: trigger_error ('Something went wrong!',  E_USER_NOTICE); // Throws a user warning: trigger_error ('Something went REALLY wrong!', E_USER_WARNING); // Throws a user error: trigger_error ('It\'s completely broken!', E_USER_ERROR); ?>
  2. [quote author=ozPATT link=topic=101907.msg403840#msg403840 date=1153922262] this is a cool class to do what you want... usage is at the bottom, and you can either upload with no validation, or with. pretty easy to get your head around, just copy all this into a file, call it something like class.fileupload.php, and include that in your page. then use the usage instructions at the bottom, wherever you want to use it. [code]<?php   class Upload_Files { //vars var $temp_file_name; var $file_name; var $upload_dir; var $upload_log_dir; var $max_file_size; var $banned_array; var $ext_array;     //Validation of file extensions function validate_extension() { //set vars $file_name = trim($this->file_name); $extension = strtolower(strchr($file_name, ".")); $ext_array = $this->ext_array; $ext_count = count($ext_array); //start validation process if(!$file_name) { return false; } else { if(!$ext_array) { return true; } else { //put extensions into an array foreach($ext_array as $value) { $first_char = substr($value, 0, 1); if($first_char <> ".") { $extensions[] = "." . strtolower($value); } else { $extensions[] = strtolower($value); } }   //find out if the extension is valid foreach($extensions as $value) { if($value == $extension) { $valid_extension = true; } }   //is the $valid_extension variable present? if($valid_extension) { return true; } else { return false; } } } } //validation of file size function validate_size() { $temp_file_name = trim($this->temp_file_name); $max_file_size = trim($this->max_file_size); if($temp_file_name) { $size = filesize($temp_file_name); if($size > $max_file_size) { return false; } else { return true; } } else { return false; } } //does file already exist? function existing_file() { $file_name = trim($this->file_name); $upload_dir = $this->get_upload_directory(); if($upload_dir == "ERROR") { return true; } else { $file = $upload_dir . $file_name; if(file_exists($file)) { return true; } else { return false; } } } //extract the file size function get_file_size() { $temp_file_name = trim($this->temp_file_name); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($temp_file_name) { $size = filesize($temp_file_name); if($size < $kb) { $file_size = "$size Bytes"; } elseif($size < $mb) { $final = round($size/$kb, 2); $file_size = "$final KB"; } elseif($size < $gb) { $final = round($size/$mb, 2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb, 2); $file_size = "$final GB"; } else { $final = round($size/$tb, 2); $file_size = "$final TB"; } } else { $file_size = "ERROR NO FILE PASSED TO get_file_size()"; } return $file_size; } //extract the max file size function get_max_size() { $max_file_size = trim($this->max_file_size); $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; if($max_file_size) { if($max_file_size < $kb) { $max_file_size = "$max_file_size Bytes"; } elseif($max_file_size < $mb) { $final = round($max_file_size/$kb, 2); $max_file_size = "$final KB"; } elseif($max_file_size < $gb) { $final = round($max_file_size/$mb, 2); $max_file_size = "$final MB"; } elseif($max_file_size < $tb) { $final = round($max_file_size/$gb, 2); $max_file_size = "$final GB"; } else { $final = round($max_file_size/$tb, 2); $max_file_size = "$final TB"; } } else { $max_file_size = "ERROR: NO SIZE PARAMETER PASSED TO get_max_size()"; } return $max_file_size; } //validation of the user function validate_user() { $banned_array = $this->banned_array; $ip          = trim($_SERVER['REMOTE_ADDR']); $cpu          = gethostbyaddr($ip); $count        = count($banned_array); if($count < 1) { return true; } else { foreach($banned_array as $key => $value) { if($value == $ip . "-" . $cpu) { return false; } else { return true; } } } } //verify the upload directory function get_upload_directory() { $upload_dir = trim($this->upload_dir); if($upload_dir) { $ud_len = strlen($upload_dir); $last_slash = substr($upload_dir, $ud_len-1, 1); if($last_sleash <> "/") { $upload_dir = $upload_dir . "/"; } else { $upload_dir = $upload_dir; } $handle = @opendir($upload_dir); if($handle) { $upload_dir = $upload_dir; closedir($handle); } else { $upload_dir = "ERROR"; } } else { $upload_dir = "ERROR"; } return $upload_dir; } //verify the upload log directory function get_upload_log_directory() { $upload_log_dir = trim($this->upload_log_dir); if($upload_log_dir) { $ud_len = strlen($upload_log_dir); $last_slash = substr($upload_log_dir, $ud_len-1, 1); if($last_slash <> "/") { $upload_log_dir = $upload_log_dir . "/"; } else { $upload_log_dir = $upload_log_dir; } $handle = @opendir($upload_log_dir); if($handle) { $upload_log_dir = $upload_log_dir; closedir($handle); } else { $upload_log_dir = "ERROR"; } } else { $upload_log_dir = "ERROR"; } return $upload_log_dir; } //upload the file with no validation function upload_file_no_validation() { $temp_file_name = trim($this->temp_file_name); $file_name      = trim(strtolower($this->file_name)); $upload_dir    = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size      = $this->get_file_size(); $ip            = trim($_SERVER['REMOTE_ADDR']); $cpu            = gethostbyaddr($ip); $m              = date("m"); $d              = date("d"); $y              = date("Y"); $date          = date("m/d/Y"); $time          = date("h:i:s A"); if(($upload_dir == "ERROR") || ($upload_log_dir == "ERROR")) { return false; } else { if(is_uploaded_file($temp_file_name)) { if(move_uploaded_file($temp_file_name, $upload_dir . $_SESSION['uid'] . '_' . $file_name)) { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; $fp = fopen($log, "a+"); fwrite($fp, "$ip-$cpu | $file_name | $file_size | $date | $time"); fclose($fp); return true; } else { return false; } } else { return false; } } } //upload file with validation function upload_file_with_validation() { $temp_file_name = trim($this->temp_file_name); $file_name      = trim(strtolower($this->file_name)); $upload_dir    = $this->get_upload_directory(); $upload_log_dir = $this->get_upload_log_directory(); $file_size      = $this->get_file_size(); $ip            = trim($_SERVER['REMOTE_ADDR']); $cpu            = gethostbyaddr($ip); $m              = date("m"); $d              = date("d"); $y              = date("Y"); $date          = date("m/d/Y"); $time          = date("h:i:s A"); $existing_file  = $this->existing_file(); $valid_user    = $this->validate_user(); $valid_size    = $this->validate_size(); $valid_ext    = $this->validate_extension(); if(($upload_dir == "ERROR") || ($upload_log_dir == "ERROR")) { return false; } elseif((((!$valid_user) || (!$valid_ext) || (!$valid_size) || ($existing_file)))) { return false; } else { if(is_uploaded_file($temp_file_name)) { if(move_uploaded_file($temp_file_name, $upload_dir . $file_name)) { $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt"; $fp = fopen($log, "a+"); fwrite($fp, "$ip-$cpu | $file_name | $file_size | $date | $time"); fclose($fp); return true; } else { return false; } } else { return false; } } } } //usage /* $upload_class = new Upload_Files; $upload_class->temp_file_name = trim($_FILES['upload']['tmp_name']); $upload_class->file_name = trim(strtolower($_FILES['upload']['name'])); $upload_class->upload_dir = "uploads/"; $upload_class->upload_log_dir = "uploads/upload_logs/"; $upload_class->max_file_size = 524288; $upload_class->banned_array = array(""); $upload_class->ext_array = array(".jpg", ".gif", ".jpeg", ".png"); $valid_ext = $upload_class->validate_extension(); $valid_size = $upload_class->validate_size(); $validate_user = $upload_class->validate_user(); $max_size = $upload_class->get_max_size(); $file_size = $upload_class->get_file_size(); $upload_directory= $upload_class->get_upload_directory(); $upload_log_directory = $upload_class->get_upload_log_directory(); $upload_file = $upload_class->upload_file_with_validation(); */ ?> [/code] any questions, just ask... [/quote] Thanks ozPATT but I need it for a project and need to be able explain the code.
  3. Hi as the subject says I am trying to upload an image to the server and at the same time add the url to the database. I have achieved both seperately but I am have difficulty combining them. Here is the code I am trying. [color=green]<form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form>[/color] This the form to browse for image and pass it to the uploaderphp file which uploads the file to the server. This is where I am struggling. I have the results from the upload form passed to the uploader.php page and I am trying to pass it onto the uploaderupdate.php but I am having no success in passing the variable stored as file. Here are the uploader.php [color=red]<form name="load" action="uploaderupdate.php" method="post"> <?php // Where the file is going to be placed $target_path = "C:\kev\ "; /* Add the original filename to our target path.  */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {     echo "The file ".  basename( $_FILES['uploadedfile']['name']).  " has been uploaded to folder $target_path"; }     else {     echo "There was an error uploading the file, please try again!"; } $file = $target_path; echo $file; $file = 'file'; echo $file;   ?>   <tr> <td><input type='hidden' name='file' /></td> <td valign = "top"><input type="submit" name="submit" value="Add new photo"></td> </tr>       <?php ?> </form>[/color] and uploaderupdate.php files. [color=navy]<?php   $user  = $_POST['file']; $user  = strtoupper($user);       echo $user;       ?>[/color]
  4. [quote author=wildteen88 link=topic=101782.msg403107#msg403107 date=1153828717] You'll need to create a form first, which will state where the data will be sent to and the method (GET/POST) then use javascript to submit the form, using the onchange attribute for the drop down menu. Like so: [code]<form action="page.php" name="album" method="post">   <select name="album_name" onchange="document.album.submit()"> <?php       $usrname = $_COOKIE[user_cookie];       $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");       $stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");       OCIExecute($stmt);       echo "Executed";       while (OCIFetch($stmt))       {       $record =OCIResult($stmt, 'ALBUM_NAME');       echo " <option value = '$record'> $record</option>";       }   OCIFreeStatement($stmt);   OCILogoff($conn);   ?>   </select> </form>[/code] Change page.php to the page you want the form to be submitted to. [/quote] Thank you it was the [color=blue](onchange="document.album.submit()")[/color] that I was missing.
  5. [quote author=SemiApocalyptic link=topic=101782.msg403105#msg403105 date=1153828566] I don't think the select tag accepts a method attribute. You'll need to enclose it in a form... [code]<form name="myform" action="page2.php" method="post">     <select name="myselect">         <option value="1">ONE</option>         <option value="2">TWO</option>     </select> </form>[/code] [/quote] Sorry I should have stated that I do have it cotained in a form as I am passing other variables of which all work, but these are simple inputs held within a table.
  6. Hi I am having trouble passing a variable form a dropdown list retrieved from a database table and trying to pass it to another page but it won't pass it for some reason. [color=blue]Here is the select from page 1 <select method="post" name = "album_name"> <?php       $usrname = $_COOKIE[user_cookie];             $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");             $stmt = OCIParse($conn, "select * from album where user_name = '$usrname' ");             OCIExecute($stmt);       echo "Executed";           while (OCIFetch($stmt))       {       $record =OCIResult($stmt, 'ALBUM_NAME');       echo " <option value = '$record'> $record</option>";             }         OCIFreeStatement($stmt); OCILogoff($conn); ?> </select>[/color] [color=red] Here is how I am trying to show it on page 2 $album_name = $_POST['album_name']; echo $album_name; [/color]
  7. Cheers HeyRay2 working fine now. I thought it was something to do with converting from MySQL to Oracle. But thats how you grow from being a newbie. Thanks again.
  8. [quote author=HeyRay2 link=topic=101332.msg401221#msg401221 date=1153494471] What problem are you having with the code? Are you getting error messages? Is your table not printing correctly? A little more information is needed before we can truly help... :) [/quote] I am getting a blank page at the moment. The first code I posted returned the data in 2 columns down the page where I would like rows going across the page in say 6 columns and drop down for a new row.
  9. [quote author=thorpe link=topic=101332.msg400980#msg400980 date=1153452850] This topic is covered in the FAQ/Code sepository. [url=http://www.phpfreaks.com/forums/index.php/topic,95426.0.html]Here[/url]. [/quote] As I have said I am new to PHP and coding in general I have tried following the code in the link but have had no success especially as I use Oracle database and the code is for MySQL. I have posted my code below any help would be appreciated. [color=blue]<?php $usrname = $_COOKIE[user_cookie]; $conn = OCILogon("kevin", "kevin", "") or die ("connection failed");       $stmt = OCIParse($conn, "select * from product where user_name = '$usrname' ");       OCIExecute($stmt);       $img = OCIResult($stmt,'IMAGE');       if($stmt > 0) {     $i = 0;     $max_columns = 3;         while (OCIFetch($stmt))   {       // make the variables easy to deal with       extract($row);       // open row if counter is zero       if($i == 0)           echo "<tr>";       // make sure we have a valid product       if($img != "" && $img != null)           echo "<td>$img</td>";           // increment counter - if counter = max columns, reset counter and close row       if(++$i == $max_columns)       {           echo "</tr>";           $i=0;       }  // end if   } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) {     for($j=$i; $j<$max_columns;$j++)         echo "<td>&nbsp;</td>"; OCIFreeStatement($stmt); OCILogoff($conn); } ?>[/color]
  10. [color=green]Sorry if this topics in the wrong place but I am new to this coding.[/color] As the subject say I am retrieving data from two database columns and would like to put it into multi columns. I can retrive it to appear in two columns no problem. The results currently go down the page where as I would like them to go across for say six columns and then automaticaly start a new row. Is there any way of setting the coumnls at six? I know it looks like I am not closing the <a> tag but I am it just shows up like [/url] for some strange reason.  Here is the code I am using. [color=blue]while (OCIFetch($stmt))       {           $img = OCIResult($stmt,'IMAGE'); $titl = OCIResult($stmt,'TITLE'); echo " <table> <tr> <td><a href=". $img ." target='new'><img src=' " . $img . "' height='75' width='100'></a> </td> </tr> <tr> <td> $titl </td> </tr> </table>";       } [/color]
  11. [quote author=wildteen88 link=topic=101273.msg400629#msg400629 date=1153417971] Use the img code: [code][img]img-url-here[/img][/code] tags, if you want to place a screen shot [/quote] The img tag aren't working or at least I can't see the image in preview. but this is what I am getting. The code is also below.           >:(         angry           :(         sad           :'(           cry    This is what I get   >:(        :(          :'(      angry      sad        cry    This is what I would like Any way I hope you get the idea. [color=red] while (OCIFetch($stmt))       {           $img = OCIResult($stmt,'IMAGE'); $titl = OCIResult($stmt,'TITLE'); echo " <table> <tr> <td><a href=". $img ." target='new'><img src=' " . $img . "' height='75' width='100'></a>; </td> </tr> <tr> <td> $titl </td> </tr> </table>";       }[/color]
  12. [quote author=HeyRay2 link=topic=101273.msg400615#msg400615 date=1153417113] Can you link the page you are creating so we can see exactly what you are seeing? [/quote] The sites not live yet. Is there a way to insert a screen shot?
  13. [quote author=treilad link=topic=101273.msg400585#msg400585 date=1153414953] Yes, I know. But since I don't have that table I just used text. Have you tried mine, substituting your code in? [/quote] I've managed to get it to work with the title under the image thanks. The only prolem now is that they are in a single colum down the page instead of across the page in a row.
  14. [quote author=treilad link=topic=101273.msg400585#msg400585 date=1153414953] Yes, I know. But since I don't have that table I just used text. Have you tried mine, substituting your code in? [/quote] Yes your code works but when I replace the TITLE for colum TITLE retrieved from the table it goes back to the side.
  15. [quote author=king arthur link=topic=101273.msg400563#msg400563 date=1153413806] You haven't closed the anchor tag, e.g. with [code] </a> [/code] after the img tag. [/quote] thanks but closing the img tag has no effect.
×
×
  • 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.