Jump to content

Lefteris

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Everything posted by Lefteris

  1. A yeah session start! Now I remember. And you gotta put it before everything in the page, even the <head> tag, I think. Thanks for the help wayne. I will get on to it right away
  2. Thanks for your reply, what I actually meant is not exactly that but we can start from there. Looking at your example $button_pressed is true now. True for how long? If I refresh the page with a meta http-equiv a little later down in the code , will it still be set? That's what I meant to ask. From the things I tried it seems it will not be set. I have totally forgotten how php works, there must have been some kind of global variable type for that purpose.
  3. Oh so that if returns true if the form exists! Now all is clear to me at least as far as the form problem is concerned. I already solved it taking into account the actual usage of that if. Thanks wayne. About the other thing I said do you have any idea :
  4. Hello all, It has been a long time since I last touched php and I notice that many things are not as I thought them to be. Just so I can remember I set out to make a simple news script which will communicate with a mysql Database which will keep my site's news. This should be simple but here are the questions. So, I have a .php file to use as news addition file. This outputs a form like that: <FORM ACTION="<?php echo(recentURL(true) ); ?>" METHOD=POST> <p>Type the authors name here:<BR> <input size="25" NAME="author"> <p>Type news title here:<BR> <input size="25" NAME="newsTitle"> <P>Type your news here:<BR> <TEXTAREA NAME="newsText" ROWS=10 COLS=40 WRAP> </TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME="submitNews" VALUE="SUBMIT"> </FORM> Right below the form from what little php I remembered I opened an if statement like that : if (isset($_POST['submitNews'])) { Inside the statement is the sql db connection code. The problem is that from the very start this if returns true. As a result whenever I load the page, or refresh it I have additions to the database. Any idea what could be wrong? Or do you need more code? Another question I would like to ask is about variables. Let's say I have a variable which is not set. But I set it right after I click a button, and that button refreshes the page. When the page refreshes that variable should be set, right? In the code I am trying out it refreshes and the variable is not set. Thanks in advance for the answers people
  5. Hello and thanks for the reply. I did what you said and just used the constructor it inherited from its parent class but I still get an error at the same line, only this time it is a very different one. Call to a member function do() on a non-object in ... blah blah Still Following the example code I put it this topic. Any idea why I get this?
  6. Hello all. I have had several problems with php inheritance. I am used to the way c++ deals with inheritance so I thought I could inherit constructors somehow. Seems I can't. But my newest problem is this. I will show you an example of it with the following code: class parent { private $other; public function __construct() { $this->other = new Other(); } public function doSomething() { $this->other->do(); } } class child extends parent { public function __construct() { $this->other = new Other(); } public function newFunction() { parent::doSomething(); } } When I make a new child ... and call the newFunction() I get a: Fatal error: Cannot access empty property in the line where the parent's doSomething has the other object. Which means it is empty. But why is it empty? Isn't that the same object I am instantiating at the child's constructor? I wanted to make my code a little more neat ... a little more OOP and now I think I just killed my code
  7. Hey I am sorry to bump my own topic but it seems it got lost under many new topics and got left with no answer.
  8. Hello all. I have a problem. Up to now the call to $_SERVER['PHP_SELF'] call worked like a charm in any form in my website. Now I made something like ... a dynamic form generation. I am making the various forms by use of Javascript. LAter the javascript function is called inside a php script. Example of code : function fillSetArt(div) { //we load the XML file into xmlAudioObj xmlArtObj = loadXML(xmlArtObj,'artsoft.xml'); //this will be the function which will read the file and extract the data we need! xmlArtObj.onreadystatechange = function() { var text = '<form name="userSkills" id="userSkills" action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="POST">'; I added the form's declaration and well .. everything inside a javascript script which edits the inner html attribute of the DIV which I want to contain the various forms. The problem is that when I do it this way I get : Access forbidden! You don't have permission to access the requested object. It is either read-protected or not readable by the server. If you think this is a server error, please contact the webmaster. Error 403 localhost 06/18/08 11:23:07 Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5 And in the browser I can see that the error is thrown due to the PHPSELF call. Any idea how to get around this error?
  9. Aha I see. Thanks a lot, makes sense that I would have to save it somewhere. Sounds like a lot of trouble but I feel really organized by having user images in the db instead of in a file. I will try to implement it and post back when I do. Thanks again.
  10. Thanks a lot friend, but I still have a problem. Turned out I had errors in the above code so it never went to the imagecopyresampled part. In particular I never checked the width and height of the image correctly. I tried to do it as I had done but it did not accept $_FILES['userpic']['tmp_name'] as either a destination image or a source image for the image copy resampled. So I then tried it your way, like in the script you linked but a lot simpler since I just want to resize everything to 150x150. The problem is ... how do you store this image in the database? I used to store images in the database by doing something like that : $fcontents = file_get_contents($img_dst); and then adding it with mysql_real_escape_string($fcontents) But now img_dst is not a filename somewhere in the server, it is an image resource. How do you store it in the database? Moreover I can't check to see if the resizing took place if I don't store it in the DB since I already have headers on the top of the page and can't see the image with a simple imagejpeg($img_dst). Here is the code : //get its dimensions $dimensions = getimagesize($_FILES['userpic']['tmp_name']); $imgwidth = $dimensions[0]; $imgheight = $dimensions[1]; //if the dimensions don't fit then resize it! if($imgwidth != 150 || $imgheight != 150) { $img_dst=imagecreatetruecolor(150,150); $img_src = imagecreatefrompng($_FILES['userpic']['tmp_name']); //resize using this ultra cool function! Really cool! imagecopyresampled($img_dst,$img_src,0,0,0,0,150,150,$imgwidth,$imgheight); }
  11. This is not php code. This is a shell script. Jonsjava just gave you the phpcode to run the script. It searches the public_html directory of your website and finds all the files, then inside those files it erases all the functions which contain : var .* return( parseInt(.*') In regular expressions .* means any zero or more characters, so this effectively deletes all the function which contain this. Maybe this is the malware code your webhosting company detected so they made this shell script for you to run. But ofcourse since I am no expert I might be wrong
  12. Sorry for bumping my own topic but since it got only 4 views I assume it got buried due to lots of new topics and none got a change to see it. So ... anyone got any idea how to properly resize an image with php? Why is my way wrong?
  13. Hello all, I have a problem. I can't resize images with imagecopyresampled. Here is my code : .... .... //if the size of the image is greater than 200 kbs if($_FILES['userpic']['size'] > 204800) die("Please upload an image with size lower than 200 Kbs"); //get its dimensions $dimensions = getimagesize($_FILES['userpic']['tmp_name']); //if the dimensions don't fit then resize it! if($dimensions['width'] > 150 || $dimensions['height'] > 150) { imagecopyresampled($_FILES['userpic']['tmp_name'],$_FILES['userpic']['tmp_name'],0,0,0,0,150,150,$dimensions['width'],$dimensions['height']); } $fcontents = file_get_contents($_FILES['userpic']['tmp_name']); //store the image in the db $sql->updatetable("users","userImage","'".mysql_real_escape_string($fcontents)."'","username","'".$username."'"); //and its type $sql->updatetable("users","userImageType","'".$extension."'","username","'".$username."'"); ... ... Shouldn't this work? It is not working. Actually ... it worked a little ... but the resizing was completely out of proportion. It should get resized to 150x150 but it got resized to 280x212 pixels. Any idea why? Also what is the appropriate way to resize an image? Thank in advance.
  14. well you could use a switch statement if you got too many checks to make: switch($var) { case condition1: case condition2: case condition3: case condition4: ..................... case conditionn: echo"fubar"; break; default: echo"not fubar "; break; }
  15. Hey mate. I am no expert but in the first statement I think you are telling php to check : if($var == condition1) or if condition2 is true. It is not comparing var to condition 2. And I guess condition 2 will always be true since it is not getting compared to something , so the whole expression will always be true so .. it will always echo"fubar"; Ofcourse I might misunderstand something but I hope I helped.
  16. You could do it like that: $fcontents = file_get_contents("yourimagepathhere"); file_put_contents("yourcopypathhere",$fcontents); Read up on file system functions if you have anymore questions
  17. Hm... that too. It WAS missing a </form> tag. So it was considering it the same form... and by putting a enctype attribute it got corrected(in a wrong way ). Now by closing the open <form> tag no enctype attribute is needed. Even more solved than before. Phew ... I can really sleep like a baby now
  18. OK HERE IT IS! : Login.php contained 2 more forms. As one would expect of a login script ofcourse. I spent the last 2 days searching for empty $_FILES reasons so I learned many different reason why this would happen. One of those was that if you have more forms in the same file with your file upload form you have to add the enctype="multipart/form-data" attribute in them too. I just did that and it works now. So yeah ... ahem ... what can I say? I feel stupid for what I went through the last 2 days to find this. Even installing a different server .... *sigh* Thanks all of you. Honestly. Especially PFMaBiSmAd, without your hint about running it standalone I would never have found it!
  19. OH MY GOD. Why did it not cross my mind to just isolate the form in a separate file. I followed your advice with this sample form : <html> <body> <form enctype="multipart/form-data" name="testF" id="testF" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="100048576" /> Enter file:<input type="file" name="tfile" id="tfile" /> <input type="submit" name="sub" id="sub" value="Upload" /> </form> <?php if(isset($_POST['sub'])) { echo("Sub clicked, got in!"); echo("<br />"); print_r($_FILES); } ?> </body> </html> Guess what I got? Array ( [tfile] => Array ( [name] => eleos.png [type] => image/png [tmp_name] => C:\xampp\tmp\php19.tmp [error] => 0 [size] => 2397 ) ) It is actually the first time I see a $_FILES being displayed. I did not know what to expect until now Which means ... that something in the other part of the code messes with ... $_FILES? Makes no sense ... this is the first time I tried to add anything file related to my site. login.php and sqlConnection both mess with my sql database and with session variables and cookies. That in mind, I will debug carefully, and debug CODE now. At least now I DO know it is not settings. It is a huge step forward. I will post again when and if I find what it was.
  20. That's easy All you gotta do is type: $FinalCat = $subsubcat."|".$subsubsubcat Edit: Damn! Was slow
  21. I guess you can play with the time and date functions to get any result you want any way you want it. For more information go here : Date and Time functions
  22. Thanks for the input mate but actually it can't be an older browser cache since I never made this form with type anything but file. On the same time it can't be a php/server configuration matter! Since I completely uninstalled the easyphp configuration saved my htmldocs from it and reinstalled another bundle (XAMPP) and moved my project and made configurations from scratch there. Still it did not work. I just tried 3 different browsers (IE,Opera,Firefox) and got the same empty $_FILES array. Yes, I got to admit that it sounds more and more like a php/server problem. But... what problem? That was my line of thinking yesterday night too, and the result was a complete uninstallation and reinstallation with another package. Getting the same result with another package should rule out that possibility, right? But if it is not that then? What? I have to admit I am completely buffled as to what I am to do next. Maybe ... try to find other ways to upload files via php .... if they exist? :/
  23. Check and see if it is a cache problem. Maybe your old css is cached in firefox. Just do a clear all private data from the Tools Menu and check if it is displayed.
  24. Thank you very much for your reply. As for the global $sql. As you can see it represents an sqlConnection object ... just a helper object I have made with various sql functions for my project. And yes you are right! It is only for functions! I did not know that. I had used it in a function the first time and then I thought that global was needed everywhere. Thanks a lot for pointing that out! Now, on to the matter at hand: Yes the code in the isset($_POST['subpic']) is executed. I print both $_POST and $_FILES. With print_r : Array ( ) Array ( [MAX_FILE_SIZE] => 100048576 [userpic] => schematic.jpg [subpic] => Upload New Picture ) The first array is the $_FILES ... unfortunately As you can see I changed the MAX_FILE_SIZE to around 100MB. I did so in php.ini too, for no particular reason. Yes php is reading php.ini . Proof for that is the following straight from phpinfo(); : Loaded Configuration File C:\xampp\apache\bin\php.ini file_uploads On On post_max_size 16M 16M upload_max_filesize 100M 100M upload_tmp_dir C:\xampp\tmp C:\xampp\tmp As for the ini_set ("display_errors", "1"); error_reporting(E_ALL); I put it in the start of my first php code but nothing was shown . Hope you can help me with this. Until I get a reply I will just keep googling and checking for every little thing.
×
×
  • 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.