Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Everything posted by Drongo_III

  1. Thanks Gizmola! That's really great advice and to be honest helps to relax me a lot! I think i am getting too caught up worrying about what might be, or how i should put this or that across when really i just need to deomstrate a confident air and an open mindedness to taking on whatever they throw my way. Really appreciate your advice and i'm very glad i asked Drongo
  2. Hi Guys This is going to sound a bit silly (and possibly off topic entirely) but my motto in life is that if you don't accept your ignorance and ask a question then you'll just be ignorant forever. So with that in mind.... I'm going for a job with a big web company as a project manager. The interview is going to be a group interview with a handful of candidates. I've never in my life been a group interview and although i have experience in this field i am naturally quite apprehensive about what to expect - and i want this job so badly i would eat my feet to get it. So does anyone here work for any big web companies and have you had any experience with group interviews in this setting? Any advice, tips, or suggestions on possible questions and format would be very welcome! Drongo
  3. Worked a treat! Thank you very much
  4. Hi TenDoLLA I did as you suggested - didn't know that existed. But the result has left me a little confused. I did : var_dump($_FILES["file"]["type"]); echo "<br/><br/>"; var_dump($_FILES["file"]["size"]); And got the result string(24) "application/vnd.ms-excel" int(50) Which didn't mean a whole lot to me. I would love an explanation of that. Any suggestions based on the var dump? Thanks Drongo
  5. Hi Guys Can someone see where I'm going wrong with this upload script. It's meant to only accept csv files. when i try it out all i get is is the error "invalid file" but i'm uploading a csv file. Upload form <html> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> Upload script <?php if ((($_FILES["file"]["type"] == "text/csv")) && ($_FILES["file"]["size"] < 200000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Any help would be appreciated. Drongo
  6. Ha thanks Wizard. That makes perfect sense. I was searching around for "file type" not knowing they were called mime types... It all makes sense now Thank you!
  7. Hi Guys I'm writing a script to allow for file uploads on the front end of a site. I want to restrict the file upload to csv files only. I can find examples for images such as if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) {Code goes here } But what do you use for CSV files? And why does this example use image/ before the file type? Sorry i know these are newbie questions but still new to this. thanks Drongo
  8. Well solved this noob problem now! For anyone who may, at the start of the php career, be similarly perplexed here is what i did... <?php $builder = "<table>\n"; $row = 0; $handle = fopen("testfile.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row == 0) { // this is the first line of the csv file // it usually contains titles of columns $num = count($data); $builder = $builder . "\n<tr>"; $row++; for ($c=0; $c < $num; $c++) { $builder = $builder . "<td>" . $data[$c] . "</td>"; } $builder = $builder . "</tr>\n\n<tbody>"; } else { // this handles the rest of the lines of the csv file $num = count($data); $builder = $builder . "<tr>"; $row++; for ($c=0; $c < $num; $c++) { $builder = $builder . "<td>" . $data[$c] . "</td>"; } $builder = $builder . "</tr>\n"; } } fclose($handle); $builder = $builder . "</tbody>\n</table>"; echo $builder; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $builder); fclose($fh); ?> Sorry for posting such a silly question i just couldn't figure it at first :/ Drongo
  9. Hi Guys I'm trying to create a little script that can read in a csv file and then write this as html to a text file. I'm ok reading in the csv and generating the html table in browser but i'm at a loss as to how i can pass this newly create html table into a variable to pass to the filewrite. What i want to acheive is a text file with the html code for the table. echo "<table>\n"; $row = 0; $handle = fopen("testfile.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row == 0) { // this is the first line of the csv file // it usually contains titles of columns $num = count($data); echo "<thead>\n<tr>"; $row++; for ($c=0; $c < $num; $c++) { echo "<th>" . $data[$c] . "</th>"; } echo "</tr>\n</thead>\n\n<tbody>"; } else { // this handles the rest of the lines of the csv file $num = count($data); echo "<tr>"; $row++; for ($c=0; $c < $num; $c++) { echo "<td>" . $data[$c] . "</td>"; } echo "</tr>\n"; } } fclose($handle); echo "</tbody>\n</table>"; Still very new to php so any advice or help would be appreciated. Thanks, Drongo
  10. Hi Mike Well that did the trick! I knew my thinking had gone astray somewhere. I didn't realise returning in a loop ended the loop. My unenlightened logic thought that if it found an empty instance then it would return false and the break would stop the loop. Lesson learned. Your code worked a treat Thank you very much! Drongo
  11. Hi Guys I'm a noobie to this...still. I'm starting to get into oop and I've tried to right a simple validation class. The code I've created (assuming it's right) takes the POST array, runs a validation array against it and then iterates through the validation array to see if there are any empty values. My thought was is there's an empty value it should return false, stop the itterating through the array and thereby i'll know something isn't validated and i can execute some code (at the moment it just echos either valid or invalid) I think i have gone wrong on the foreach part though because if the first array element is ok then it just displays that everything is valid - even if the other array elements are empty. I think maybe the "break" statement isn't doing what i think it should and stopping the loop. But i may be totally wrong. Can anyone tell me where i'm going wrong please and suggest a better method along the lines of what i have created. Many thanks, Drongo - noobie phper :/ class registration { // Validatation options array public $validation_options = array( 'login' =>array('filter'=>FILTER_VALIDATE_EMAIL), 'password' =>array('filter'=>FILTER_VALIDATE_STRING), 'age' =>array('filter'=>FILTER_VALIDATE_INT) ); // Filter user input and direct accordingly function filters() { $this->validated = filter_input_array(INPUT_POST, $this->validation_options ); foreach($this->validated as $key => $value) { if (empty($value)) { return false; break; } else { return true; } } } function activate() { $this->filters(); if ($this->filters() == false) { echo "Not valid sorry"; } elseif ($this->filters() == true) { echo "all valid my son"; } } } $reg = new registration(); //$db->filters(); $reg->activate(); ?>
  12. Well after an hour of scratching my head I got it to work. Thought I'd post it here to help any others in the noob boat I think i need to seriously bone up on my jquery... <script> $(function() { $( "#selectable" ).selectable({ stop: function() { $("#selectable li").click(function() { var tester = $(this).attr("value"); $("#content").html(tester); }); } }); }); </script> </head> <body> <div class="demo"> <ol id="selectable"> <li class="ui-state-default" value="100">1</li> <li class="ui-state-default" value="200">2</li> <li class="ui-state-default" value="300">3</li> <li class="ui-state-default" value="400">4</li> <li class="ui-state-default">5</li> <li class="ui-state-default">6</li> <li class="ui-state-default">7</li> <li class="ui-state-default">8</li> <li class="ui-state-default">9</li> <li class="ui-state-default">10</li> <li class="ui-state-default">11</li> <li class="ui-state-default">12</li> </ol> </div><!-- End demo -->
  13. Hi Guys I'm quite new to jquery ui and it's posing something of a headache to follow the demos :/ I'm trying to use the selectable grid (http://jqueryui.com/demos/selectable/#display-grid) and my desire is to pass a different value to a variable based on the item clicked. I'm then going to post that value to my php script. I've worked out the latter part which was pretty straight forward. But i can't work out how to retrieve a value from clicking on the grid :/ Anyone able to help? The code i'm working with is: <script> $(function() { $( "#selectable" ).selectable(); }); </script> </head> <body> <div class="demo"> <ol id="selectable"> <li class="ui-state-default">1</li> <li class="ui-state-default">2</li> <li class="ui-state-default">3</li> <li class="ui-state-default">4</li> <li class="ui-state-default">5</li> <li class="ui-state-default">6</li> <li class="ui-state-default">7</li> <li class="ui-state-default">8</li> <li class="ui-state-default">9</li> <li class="ui-state-default">10</li> <li class="ui-state-default">11</li> <li class="ui-state-default">12</li> </ol> </div><!-- End demo -->
  14. Hi Guys I'm trying to make a simple Jquery animation but IE7 is giving me some display issues. As you can see from the code below I simply have a containing div with overflow set to hidden. Within this is a large div containing two videos. When the button is clicked it simply animates the inner div left and right by adjust the margin, which displays either one of the videos. The issue is that the animation works flawlessly in firefox but in IE7 when the animation is taking place the videos momentarily spills outside of the containing div and flickers in and out of view outside of the margin of the container. I'm a bit of a loss to explain why this is happening or how to correct it as jquery is somethnig i only use very seldom. So if someone could offer some advice to correct this it would be appreciated. Thanks Drongo <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("#moving_container").animate({marginLeft:"-300px"}); }); $(".btn2").click(function(){ $("#moving_container").animate({marginLeft:"0px"}); }); }); </script> </head> <body> <div style="width: 500px; height: 500px; border: 1px solid #000; overflow: hidden"> <!-- containing div --> <div id="moving_container" style="width: 1000px; height: 500px; border: 1px solid #000; margin-top: 100px;"> <!-- Large inner div --> <div style="width: 400px; height 300px;border: 1px solid #000; float: left;"> <!--video 1 div --> <iframe width="400" height="300" src="http://www.youtube.com/embed/4TpUQD2W_Ps?rel=0" frameborder="0" allowfullscreen></iframe> </div> <div style="width: 400px; height 300px;border: 1px solid #000;float: left;"> <!--video 2 div --> <iframe width="400" height="300" src="http://www.youtube.com/embed/4TpUQD2W_Ps?rel=0" frameborder="0" allowfullscreen></iframe> </div> </div> </div> <button class="btn1">Animate</button> <button class="btn2">Reset</button> </body> </html>
  15. ooooooh...that makes a lot more sense! Just tried it with a longer string enclosing the tags and it works. TY
  16. Hi Guys Simple question. Can anyone tell me why this doesn't work please? $test = "<HEELOOOO"; $test2 = filter_var("$test", FILTER_SANITIZE_STRING); echo $test2; When I run this get I get nothing echoed back, not even in the source. So can the filter function not be used like this? I thought it would encode the special character and return it but I must be missing something simple here! Thanks, Drongo
  17. Thanks David I changed it back to the original as when i checked the source i realised nothing was happening when $name as the parameter and now you've pointed out the logic i can see why. Wrapping your head around the logical way the system deals with input is starting to click into place - slowly! Thanks for the help!
  18. Thanks JC! That helps a lot. Well I think the case of the phantom validator is solved. I shall have Watson chronicle this in my memoires Right onwards and upwards. Thanks chaps!
  19. Ahh yes you were right chaps. It was just the output to the browser. The source shows them encoded. I didn't realise it would do that - noob mistake. So that just leaves two questions: 1) Does that function does the necessaries in the correct order 2) Is it secure to pass the Post values to a variable and then clean them or should you clean straight from accessing the POST array? Thanks, Drongo
  20. Thanks Fugix I tried that but still not luck :/ I think i am cursed as nothing i seem to try works at the moment! Also, is that a rule about param names? I thought just $data would represent whatever param i supplied - i.e. so i could reuse the function on multiple types of form input. Or am i wrong?
  21. btw the variable above "$name2" was just to test the clean up process. No joy tho
  22. Hi Ken Thanks for the reply. Ooops didn't spot the closing form tag. Been staring at the screen too long. This is just a test page at the moment. The thing is this function just refuses to work and i can't figure out why. Even when i use just a variable it doesn't seem to be getting passed into the function <?php $form = "<form action='test2.php' method='POST'><input type='text' name='test' /> <input type='submit'></form>"; echo $form; $name = $_POST['test']; $name2 = '<?php echo "hello";'; class validate { function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } } $z = new validate(); echo $z->check_input($name2); ?> V confused as i can't see what is wrong :/
  23. Hi Guys Can anyone tell me why this doesn't work? <?php $form = "<form action='test.php' method='POST'><input type='text' name='test' /> <input type='submit'>"; echo $form; $name = $_POST['test']; class validate { function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } } $z = new validate(); echo $z->check_input($name); ?> Also, when it comes to validating POST data that's input via a form and retrieving it is it secure to set a variable for the Post i.e. $name = $_POST['test']; or is more secure to pass $_POST['test'] straight into the validation? It just occurs to me if you pull the post into a variable then you're inviting insecure code into your script. Though i am a complete noob at this so might be talking rubbish! Any light you can shed on why my little script isn't working would be appreciated and any tips on the best method for validating data securely would also be welcome Thank you Drongo
  24. Well that seems to work now. I can't work out what was going wrong but I kept getting a message saying it couldn't load the page "because the requested action will never complete". This was a browser generated message. Anyway retried it and it's working fine with header now. I think i'd been staring at the screen too long! Thanks for help chaps!
  25. Hi Guys Again, another noob question that I can't seem to find a concise answer to. What is the best way to append a query string to a url? I've tried using the Header() function but this didn't seem to work - i.e. Header("Location: enc.php?ID=test"); My goal is to change the query string depending on the output of various if else statements. For instance if $test isset then execute some code. The script will be self contained so it'll be posting back to itself with the query string and reacting differently depending on the query string. Any ideas? PS sorry if i am asking too many questions. Eager to learn and struggling to find answers to some things. What I basically want to do (and not sure if this is possible) is to append a different query string based on
×
×
  • 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.