helloise Posted April 19, 2011 Share Posted April 19, 2011 i have the following code: $filename = $this->getMsisdn().".png"; if (!file_exists(sfConfig::get('sf_upload_dir') . '/rainbowcode/images/profilepics/'.$filename)) { $filename = "Rainbow-code-1_blck.jpg"; //rename it to msisdn $source = imagecreatefromjpeg($filename); } i JUST want to rename "Rainbow-code-1_blck.jpg" to $this->getMsisdn().".jpg" ?? is this possible?? i want to have the SAME picture but it has a different name please help? thank you Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 19, 2011 Share Posted April 19, 2011 try: $filename = $this->getMsisdn().".png"; if (!file_exists(sfConfig::get('sf_upload_dir') . '/rainbowcode/images/profilepics/'.$filename)) { $filein = "Rainbow-code-1_blck.jpg"; // $source = imagecreatefromjpeg($filein); imagejpeg($filein, $this->getMsisdn().'.jpg') } Quote Link to comment Share on other sites More sharing options...
helloise Posted April 19, 2011 Author Share Posted April 19, 2011 i need to use filename further in the code i now have: $filename = $this->getMsisdn().".png"; if (!file_exists(sfConfig::get('sf_upload_dir') . '/rainbowcode/images/profilepics/'.$filename)) { $file_in = "Rainbow-code-1_blck.jpg"; $using_default_pic = 1; } if ($using_default_pic == 1) { $using_default_pic = 0; echo "filename before rename ".$file_in; $filename = rename($file_in,$this->msisdn."jpg"); echo "calling resize image after rename: ".$filename.'<br />'; } echo file_in gives:Rainbow-code-1_blck.jpg and echo "calling resize image after rename: ".$filename.'<br />'; gives nothing???? please help? thank you Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 19, 2011 Share Posted April 19, 2011 Don't you mean: $filename = rename($file_in,$this->getMsisdn()."jpg"); $filename will just have TRUE or FALSE based on whether it succeeded or not. Are you sure you want to just rename it or make a copy? Quote Link to comment Share on other sites More sharing options...
helloise Posted April 19, 2011 Author Share Posted April 19, 2011 thanks i fixed it but still not working echo "filename before rename ".$file_in; //gives: Rainbow-code-1_blck.jpg $filename = rename($file_in,$this->getMsisdn()); echo "calling resize image after rename: ".$filename.".jpg".'<br />'; //here $filename is empty??? yikes please help? thank you Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 19, 2011 Share Posted April 19, 2011 $filename is the result of rename, which returns TRUE or FALSE depending on whether it was able to rename the file or not... if it's blank that means it probably failed. Quote Link to comment Share on other sites More sharing options...
helloise Posted April 19, 2011 Author Share Posted April 19, 2011 thank you but can you help me with this please and show me how to achieve this so that i rename Rainbow-code-1_blck.jpg to $this->getMsisdn().".jpg" and assign $filename the value of $this->getMsisdn().".jpg" because i need to use $filename further on in my code thank you Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 19, 2011 Share Posted April 19, 2011 $file_in = "Rainbow-code-1_blck.jpg"; $filename = $this->getMsisdn().".jpg"; if(!rename($file_in, $filename)) echo "Failed to rename image."; You do understand that as soon as you run this once, the code will fail if you try to run it again, right? It won't be able to find 'Rainbow-code-1_blck.jpg' because it's been renamed. That's why I was suggesting you make a copy of it (under that new name). To do that just replace the rename call with copy. Quote Link to comment Share on other sites More sharing options...
helloise Posted April 19, 2011 Author Share Posted April 19, 2011 yikes maybe i must explain: a user registers a profile online and if he DOES NOT upload a profile pic i must use a default pic which is: "Rainbow-code-1_blck.jpg"; if he DOES upload a pic the profile pic will be saved as : $this->getMsisdn().".jpg" and i carry on with my code as per usual BUT if $this->getMsisdn().".jpg does not exist(user did not upload a profile pic) i must use Rainbow-code-1_blck.jpg BUT further along my code i need the file name to be $this->getMsisdn() AND the picture is the actual default picture just renamed.... hope this makes sense??? Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 19, 2011 Share Posted April 19, 2011 Yeah, it makes sense, but only if you copy the default profile pic. If you rename it you won't be able to use it again after the first time someone doesn't upload a pic... because it won't exist as that file name anymore. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.