Jump to content

maccy93

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Everything posted by maccy93

  1. I need to get images from a site remotely. I own and control the site I am getting trying to get the files from. I tried the following: //write the new file to disk $fh = fopen($fileLocationHost, 'w') or //get the contents of the file from the 2spring server according to the coordinates $newImage = file_get_contents('http://www.mysite.co.uk/'.$imageLocation.'/'.$imageName); //write the changes fwrite($fh, $newImage); //close the files fclose($fh); It worked... kind of. It downloaded something but the png image was unreadable. I then found this link: http://www.edmondscommerce.co.uk/php/php-save-images-using-curl/ which talks about a problem with allow_url_fopen and uses CURL to grab images from another site... however I cannot use CURL as it is disabled. Is there a way of writing an image to a server another way? Is there a way of doing this via fopen? Any help would be very much appreciated (I also cannot use fsockopen either as this is also disabled)
  2. The following is part of a class so it would be quite hard for me to show all the code here. The $image actually comes from another class, it the is path to the image on the server. Before any of this there is a file extention filter to only accept jpg, jpeg, gif and png. The variable $image comes from the upload from the user, prior to this the image goes through some resizing and cropping which works perfectly. $image is the path to the image on the server, the file name in the variable $image is 100% ok. The reason for all of this: I want all images stored in one format, png. Below first checks the file type, if jpeg jpg or gif and if so places into $imageObject If $imageObject is then empty i know the file type is already png and does not need converting, otherwise i need to convert the image to png format. The following throws no errors and the script runs. //determine image type if($this->ext == 'jpeg' || $this->ext == 'jpg') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromjpeg($image); } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.'; } } elseif($this->ext == 'gif') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromgif($image); //this is line 138 in the script. } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.'; } } //if the imageObject is empty then the image is already a png and needs no converting. if(!empty($imageObject)) { //imagepng($imageObject, $image); imagepng($imageObject, $this->path . '.png'); //now remove the old TEMP file ($image) unlink($image); } //if the imageObject is empty so simply rename the image else{ rename($image,$this->path . '.png'); } return 'success'; However I get a warning when uploading gifs (where line 138 is commented in the above code): The warning however does not stop the gif image from being uploaded, resized and coverted to a png... I just get this error in the response text. I have attached a copy of the exmaple gif i am trying to upload... there is nothing spectacular about it. Furthermore... if i upload a jpeg jpg or png I do not get any warnings... ??
  3. Hi, I have an image handling php script which works fine here if the image is actually a readable format by the php program... <?php //determine image type if($this->ext == 'jpeg' || $this->ext == 'jpg') { $imageObject = imagecreatefromjpeg($image); } elseif($this->ext == 'gif') { $imageObject = imagecreatefromgif($image); } ?> However, I tested the script with a random gif created in photoshop and i got an ugly php error returned saying the image was not the correct type for imagecreatefromgif even tho the image was a .gif file. In response I then tried to make a safety test, but it doesn't seem to work: <?php //determine image type if($this->ext == 'jpeg' || $this->ext == 'jpg') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromjpeg($image); } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.';*/ } } elseif($this->ext == 'gif') { if(imagecreatefromjpeg($image)) { $imageObject = imagecreatefromgif($image); } else{ //now remove the old TEMP file ($image) unlink($image); return 'Sorry there is a file type error with the image you are uploading.';*/ } } ?> The $image can be either a jpg jpeg gif or png... Could anyone please tell me how to correctly check if the file is in readable by the php program in this context? Any help would be very much appreciated
  4. Ah thanks a lot. That's just what I needed :-) It's always easier when you know what to look for
  5. I'm learning MVC and getting a bit confused with the accessibility of variables in classes... class Load { public $load2; } Does this mean that the variable $load2 will be accessible just by all functions within the class Load? or: Does that mean that the variable $load2 will be accessible by all other classes, eg model, controller...etc inc all the functions within?
  6. If the mod_rewrite was running perfectly on my server, shoudl the following .htaccess file in my web root change the url from www.mysite.com/route/hello to www.mysite.com?route=hello RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ index.php?route=$1 [PT] (im trying to deduce which bit i have got wrong, a server setting or my .htaccess, although the .htaccess for 403 and 404 redirects was working fine before)
  7. jcbones, thanks... but it didn't work. I have now scrapped easy php and am just testing it on my site live instead. Mod_rewite is definitely enabled on my live server as I have 404 and 403 errors usually being redirected fine. I disbaled them for the time being to see if the mod rewrite was workingL: Ok, so i'm lost... I've been following a few different guides on mod rewrite but i cant get it to work... the guy who wrote this guide http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/ uses an ifModule which i treid out but then commented out. This is my .htaccess: Options -Indexes #ErrorDocument 404 http://www.mysite.com #ErrorDocument 403 http://www.mysite.com #<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ index.php?route=$1 [PT] #</IfModule> In the index.php, i have the following to see what is getting through. Which works fine if I just go to www.mysite.com?var=value: if(!empty($_GET)) { print_r($_GET); } But if i enter www.mysite.com/route/hello I expect my index.php to print out Array ( [route] => 'hello' ) In the source. But instead I keep getting a 404 error. Have i missed something? Is there any other tests to see if mod_rewrite is working properly of not?
  8. mod rewrite on easy php: EasyPHP says to set the following in apache config : http://www.easyphp.org/faq.php#0 I have done as the guide requested on easyPHP and restarted the easyPHP. writing a modrewite into the .htaccess following this guide: http://www.debian-administration.org/articles/136 Resulted in a .htaccess like so: RewriteEngine on RewriteRule ^/route/([A-Za-z0-9]+)$ /?route=$1 [PT] With this all in place and the url of the easyPHP index page is: http: //127.0.0.1:8080/testsite/ I added a link on the home page like this: http: //127.0.0.1:8080/testsite/route/hello but the link doesnt work. the .htaccess isn't kicking in it seems. Is it not meant to be seen in the php as: http: //127.0.0.1:8080/testsite/?route=hello So that i can grab the route from the $_GET?
  9. ok, So say my apache failed or my php program failed and instead of the user accessing my domain seeing the websites pages they instead saw the source of the php, is this the extent of the damage? Would they be able to jump around my servers directory outside of the public root? Number 5 on the security guide on this site (http://www.phpfreaks.com/tutorial/php-security) talks about placing files out of the public_html and including them, however i was just wondering if a random user would ever be able to access them? EG: var/www/index.php calls for a login file: var/wwwlogins/publicLogin.php permissions on wwwlogins: user access/write/list only and owner is www-data, and as adam posted this is the username of the apache If something failed, would there be any way of a random person somehow working their way back to wwwlogins to read the publicLogin.php file, thus learning my passwords?
  10. I read a while ago that it is best to place database login files out of the web root directory on your server, and that the idea behind it was so that if someone managed to see the directory listing they would not be able to just read the login details. So, as a result i went and place my login files back one directory from the public_html and then in a new directory called 'login'. But say someone did manage to somehow see my directory listing for the public_html folder, what username would they be logged onto the server as? And is this not the same username as the php program? Thus in the permissions for my new login directory should i only allow the php program username access to it?
  11. Ha! brilliant thank your very much. That will now safe me lots and lots of time!
  12. ../ tells the php program to go up a level. require_once '../directory/somefile.php'; Is there a shortcut to go to the public web folder? For example. The following file is placed 3 folders deep: "var/www/deep/deeper/verydeep/index.php" and it requires a file with location: "var/www/thisfile.php" I there a short cut/ quicker method to?? require_once '../../../thisfile.php';
  13. or heredocs even easier still echo <<<_END heeeelllllooooo world! _END;
  14. This answered it .....: http://stackoverflow.com/questions/1993638/classes-whats-the-point in particular this bit (number8):
  15. Sorry i just realised the class namer i previously posted was missing the filtering at step two so would no make sense... <?php class namer { //passed from outside var $phpSource = NULL; //passed from inside var $varArray = array(); var $varCount = NULL; var $newVarVals = array(); var $takenVals = array(); var $newName = NULL; //1 -- Check for the variables then place all into varArray if(preg_match("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $this->phpSource)) { $array = preg_match_all("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $this->phpSource, $this->varArray); } //2 -- Filter out all the duplicates in the array, reset the numeric values and count $this->varArray = array_unique($this->varArray[0]); $varArray = array_values($this->varArray); $this->varCount = count($this->varArray); function nameGen($iterationX) { //getting a random number between 0 and the number of elements in varArray (varCount) $this->newName = rand(0,$this->varCount); //check to see if the number has not already been used if (in_array($this->newName, $this->takenVals)) { $this->nameGen($iterationX); } //if not then place the number into the takenVals so not used again and pass the new name and old name into the final array else{ $this->takenVals[] = $newName; $this->newVarVals[] = array('oldName' => $this->varArray[$iterationX],'newName' => '$_' . $this->newName); } } //4 -- loop through creating new names for all the variables in the php source for ($x = 0; $x < $this->varCount; $x++) { $this->newName = $this->nameGen($x); } //5 -- str_replace the source $newVarValsCount = count($namer->newVarVals); for($i = 0 ; $i < $newVarValsCount ; ++$i) { $phpSource = str_replace($namer->newVarVals[$i]['oldName'], $namer->newVarVals[$i]['newName'], $phpSource); } } //a -- start the class $namer = new namer(); //b -- pass the php source to the class $namer->phpSource = $phpSource; //c -- obfusicated source $source = $namer->phpSource; ?>
  16. If you need a variable like that then you could place into a session variable, that way from your description the variable would not be reset when the script is reloaded.
  17. OK, sorry for the belated reply. I'm trying to grasp the concept of a class and the point of it. The snippet from the OP was from variable renamer for php I just wrote. This is the whole thing as a function and works ok (just need to send the source as a variable to the function): <?php function simpleObfusicate($phpSource){ //1 -- Check for the variables then place all into if(preg_match("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $phpSource)) { $array = preg_match_all("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $phpSource, $varArray); } //2 -- Filter out all the duplicates in the array, reset the numeric values and count $varArray = array_unique($varArray[0]); $varArray = array_values($varArray); $varCount = count($varArray); //3 -- create new random names for each variable found and store in array with old names //setting some variables ready to catch info from the loops $newVarVals = array(); $takenVals = array(); for($i = 0 ; $i < $varCount; ++ $i) { $newName = ''; while($newName == '') { $newName = rand(0,$varCount); if(in_array($newName,$takenVals)) { $newName = ''; } } $takenVals[] = $newName; $newNameToKeep = '$_'.$newName; $newVarVals[] = array('oldName' => $varArray[$i], 'newName' => $newNameToKeep); } //4 -- now using placeholders and a foreach loop cycle though replacing the $phpsource $newVarValsCount = count($newVarVals); for($i = 0 ; $i < $newVarValsCount ; ++$i) { $phpSource = str_replace($newVarVals[$i]['oldName'], $newVarVals[$i]['newName'], $phpSource); } //5 -- return the source to the user return $phpSource; } //a -- call the function into a variable $source = simpleObfusicate($phpSource) ?> But then phporcaffeine turned my while loop back into a function and then placed it in a class so the function could do what i originally thought... be called in a loop... but i don't really get the purpose of a class. I mean arent they really just the same as functions? I've just read up a little about classes and had a go at changing phporcaffeine class to embody all of the function simpleObfusicate: <?php class namer { //passed from outside var $phpSource = NULL; //passed from inside var $varArray = array(); var $varCount = NULL; var $newVarVals = array(); var $takenVals = array(); var $newName = NULL; //1 -- Check for the variables then place all into varArray if(preg_match("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $this->phpSource)) { $array = preg_match_all("/([$][a-zA-Z_][a-zA-Z0-9_]*)/m", $this->phpSource, $this->varArray); } //2 -- send relavent data to this class $this->varCount = count($this->varArray); function nameGen($iterationX) { //getting a random number between 0 and the number of elements in varArray (varCount) $this->newName = rand(0,$this->varCount); //check to see if the number has not already been used if (in_array($this->newName, $this->takenVals)) { $this->nameGen($iterationX); } //if not then place the number into the takenVals so not used again and pass the new name and old name into the final array else{ $this->takenVals[] = $newName; $this->newVarVals[] = array('oldName' => $this->varArray[$iterationX],'newName' => '$_' . $this->newName); } } //4 -- loop through creating new names for all the variables in the php source for ($x = 0; $x < $this->varCount; $x++) { $this->newName = $this->nameGen($x); } //5 -- str_replace the source $newVarValsCount = count($namer->newVarVals); for($i = 0 ; $i < $newVarValsCount ; ++$i) { $phpSource = str_replace($namer->newVarVals[$i]['oldName'], $namer->newVarVals[$i]['newName'], $phpSource); } } //a -- start the class $namer = new namer(); //b -- pass the php source to the class $namer->phpSource = $phpSource; //c -- obfusicated source $source = $namer->phpSource; ?> There is actually more code required to convert it as a class. If the class and the function were kept in separate files then both would be need to be called with require_once or other but then the class version would require more code again to get the same result. http://www.phpbuilder.com/board/archive/index.php/t-10379417.html These guys say "helps decreasing redundancy and making coding alot easier". So i'm guessing then for much more complex coding the classes come into their own...?
  18. Cool, thanks. Sorry I only just came back on here and saw it now. I'll have to have a look at that in the morning tho now I don't really know anything about OOP yet so that's cool thanks!
  19. To assign $newName a number between 0 and the count of $varCount on the proviso that the number has not already been used for use further down. Nightslyr, thanks That's awesome!
  20. Hmm, when i put the function out of the for loop I got the $newName to just be empty all the time. I removed the function and just put a while loop in and it worked: $newVarVals = array(); $takenVals = array(); $varCount = count($varArray); for($i = 0 ; $i < $varCount; ++ $i) { $newName = ''; while($newName == '') { $newName = rand(0,$varCount); if(in_array($newName,$takenVals)) { $newName = ''; } } $takenVals[] = $newName; $newNameToKeep = '$_'.$newName; $newVarVals[] = array('oldName' => $varArray[$i], 'newName' => $newNameToKeep); }
  21. Is this even possible? I'm trying to call function nameGen from in the function nameGen but I just get an error saying cannot redeclare. I only want it to return $newName when it is not in the array $takenVals. can this only be done with another loop and a constant somewhere? $newVarVals = array(); $takenVals = array(); $varCount = count($varArray); // contents are set else where and is fine for($i = 0 ; $i < $varCount; ++ $i) { function nameGen(&$varCount,&$takenVals){ $newName = rand(0,$varCount); if(in_array($newName,$takenVals)) { nameGen(&$varCount,&$takenVals); } else{ return $newName; } } $newName = nameGen(&$varCount,&$takenVals); $takenVals[] = $newName; $newNameToKeep = '$_'.$newName; $newVarVals[] = array('oldName' => $varArray[$i], 'newName' => $newNameToKeep); } error: Cannot redeclare nameGen()
  22. http://www.google.co.uk/search?gcx=c&sourceid=chrome&ie=UTF-8&q=php+check+mobile+browser You can check the browser the client is viewing you site from
  23. Ahhh... cool thanks. I couldn't find how to do that using w3schools so was about to give up thanks a lot
  24. I don' think I asked my question correctly. The following example from w3 schools uses this xml file: <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> <book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book> <book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book> </bookstore> And then the following script gets and prints on a new line all the text from the price tags. <html> <body> <script type="text/javascript"> function loadXMLDoc(dname){ if (window.XMLHttpRequest){ xhttp=new XMLHttpRequest(); } else{ xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; } //getting the xml into a var to parse xml=loadXMLDoc("books.xml"); //the path in question path="/bookstore/book/price/text()" ////how can i change this to only select the prices of the books where the category="COOKING" ? // code for IE if (window.ActiveXObject){ var nodes=xml.selectNodes(path); for (i=0;i<nodes.length;i++) { document.write(nodes[i].nodeValue); document.write("<br />"); } } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument){ var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE,null); var result=nodes.iterateNext(); while (result) { document.write(result.nodeValue + "<br />"); result=nodes.iterateNext(); } } </script> </body> </html> Is it possible to change the path so that the script will only print out the text of the prices tag where parent tag 'book' has a category of 'COOKING' ?? I'm really stuck and can't seem to find out how to get it. Any help would awesome
  25. From w3 schools: http://www.w3schools.com/xpath/xpath_examples.asp which uses a book xml example which looks like: <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> <book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book> </bookstore> I'm trying to learn how to use xml but i can't seem to get it with w3schools. I want to be able to just select the book of 'category="COOKING"' In the example - http://www.w3schools.com/xpath/tryit.asp?filename=try_xpath_select_pricenodes_35 it manages to select all prices under 35 by using the following path: path="/bookstore/book[price>35]/price"; How can I change this to something like: path="/bookstore/book[category="COOKING"]/price";
×
×
  • 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.