Jump to content

maccy93

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

maccy93's Achievements

Newbie

Newbie (1/5)

0

Reputation

  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; ?>
×
×
  • 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.