IG88 Posted July 23, 2008 Share Posted July 23, 2008 I have this function to upload User images, but I need it to either rename or simply add a time() or date() stamp to the file name. Any suggestions? function CreateUserImage() { global $modx; $imageAttributes = str_replace(', ', ',', $this->UserImageSettings); $imageAttributes = explode(',', $imageAttributes); if ($_FILES['photo']['size'] >= $imageAttributes[0]) { $sizeInKb = round($imageAttributes[0] / 1024); $sizeError = str_replace('[+000+]', $sizeInKb, $this->LanguageArray[28]); return $this->FormatMessage($sizeError); } $userImage = $modx->config['base_path'].strtolower(str_replace(' ', '-', basename( $_FILES['photo']['name']))); if (!move_uploaded_file($_FILES['photo']['tmp_name'], $userImage)) { return $this->FormatMessage($this->LanguageArray[29]); } // License and registration ma'am. I need to se an ID! if ($modx->getLoginUserID()) { $currentWebUser = $modx->getWebUserInfo($modx->getLoginUserID()); if ($this->Type == 'manager') { $currentWebUser['username'] = $_POST['username']; } } else { $currentWebUser['username'] = $this->Username; if ($this->Username == '' || empty($this->Username)) { $currentWebUser['username'] = $_POST['username']; } } Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/ Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 http://www.php.net/rename Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597653 Share on other sites More sharing options...
IG88 Posted July 23, 2008 Author Share Posted July 23, 2008 Thank you, but that does not actually help. The line I am dealing with here is $userImage = $modx->config['base_path'].strtolower(str_replace(' ', '-', basename( $_FILES['photo']['name']))); Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597662 Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 echo out $userImage to give an example of what it looks like. Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597672 Share on other sites More sharing options...
IG88 Posted July 23, 2008 Author Share Posted July 23, 2008 I have added echo $userImage = $modx->config['base_path'].strtolower(str_replace(' ', '-', basename( $_FILES['photo']['name']))); and got nothing. I also tried echo htmlentities(var_dump($userImage)); I think I am just echoing wrong. Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597688 Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 echo $userImage; should do the trick. If it's not echoing anything, then I don't think that renaming your file is what you should be worrying about right now.. Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597705 Share on other sites More sharing options...
IG88 Posted July 23, 2008 Author Share Posted July 23, 2008 Doing that just echos out the filepath and name of the file. /home/site/public_html/assets/snippets/webloginpe/userimages/8_5_12[1].gif Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597759 Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 Well that was the point. I needed to see what to work with. You do want to rename 8_5_12[1].gif to something else right? $temp = explode(".", $userImage); $temp[0] .= time(); $userImage = implode(".", $temp); Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597768 Share on other sites More sharing options...
IG88 Posted July 23, 2008 Author Share Posted July 23, 2008 Yes that is exactly what I need to do. Adding the server time would look ugly but serve the purpose. There will be numerous seperate members uploading so it needs to be something random that will not repeat. I am just not sure why I can not get the time() to work. Thank you. Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597782 Share on other sites More sharing options...
.josh Posted July 23, 2008 Share Posted July 23, 2008 I am just not sure why I can not get the time() to work. so that codeblock didn't work? As in...it's still producing the original file, as if time() were just ""? Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597787 Share on other sites More sharing options...
IG88 Posted July 23, 2008 Author Share Posted July 23, 2008 It is not working. Very interesting though, when I right click the image and look at the properties the location shows this really long string with a hash at the end. http://www.site.com/image.php?src=/assets/snippets/webloginpe/userimages/bride_of_bob.jpg&w=100&h=100&aoe=1&hash=35dd829cf2b4ac5f79e8 Here is the code I was using. $userImage = $modx->config['base_path'].'assets/snippets/webloginpe/userimages/'.strtolower(str_replace(' ', '-', basename($_FILES['photo']['name']))); $temp = explode(".", $userImage); $temp[0] .= time(); $userImage = implode(".", $temp); if (!move_uploaded_file($_FILES['photo']['tmp_name'], $userImage)) { return $this->FormatMessage($this->LanguageArray[29]); } Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-597803 Share on other sites More sharing options...
IG88 Posted July 24, 2008 Author Share Posted July 24, 2008 Any one have any ideas? Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-598577 Share on other sites More sharing options...
IG88 Posted July 25, 2008 Author Share Posted July 25, 2008 Just hoping that some one who knows an answer will see this. Link to comment https://forums.phpfreaks.com/topic/116229-renaming-uploaded-image-fie/#findComment-599702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.