finestice Posted July 19, 2011 Share Posted July 19, 2011 ok iv searched the forum but cant find my anwser, this is my problem: iv uploaded a file and its successfully added it to /members/01/myfile.jpg now further down my script i want to rename it to /members/01/$newfile.jpg if tried using the the rename function but im thinking it only works when its in the temp folder on uploading the file. iv tried for example <? rename(/members/01/myfile.jpg, /members/01/$newfile.jpg) ?> I keep getting an error and 'file does not exist' please any ideas will be appriecated Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 try adding quotes: (I'm assuming $newfile has the name you want without .jpg <? rename('/members/01/myfile.jpg', '/members/01/'.$newfile.'.jpg') ?> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 well webstyles beat me to it 1. your arguments need to be wrapped in quotes, single or double 2. if that does not work, which it should, what is the error you receive besides "file does not exist"? 3. Are you running a windows or linux server? Quote Link to comment Share on other sites More sharing options...
finestice Posted July 19, 2011 Author Share Posted July 19, 2011 ok error im getting is: Warning: rename(/members/1/123abc123.jpg,/members/1/7.jpg) [function.rename]: No such file or directory in /home/stigros1/public_html/tyrehq.com/sell1.php on line 124 code im using is: $pid = mysql_insert_id(); $newfile = $pid; rename('/members/'.$_SESSION[id].'/123abc123.jpg', '/members/'.$_SESSION[id].'/'.$newfile.'.jpg'); any ideas iv been racking my brains out trying to figure it out Quote Link to comment Share on other sites More sharing options...
WebStyles Posted July 19, 2011 Share Posted July 19, 2011 No such file or directory means the file does not exist. check folder and filenames, remember that on unix systems they are case-sensitive. Quote Link to comment Share on other sites More sharing options...
finestice Posted July 19, 2011 Author Share Posted July 19, 2011 yes the file does exist in /members/1/123abc123.jpg - like i said the file does orginally upload ok into that folder its just the renaming it thats a problem Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 perhaps this could be a file path issue? Let's try to debug this a little $pid = mysql_insert_id(); $newfile = $pid; $old_file = "/members/{$_SESSION[id]}/123abc123.jpg"; $new_file = "/members/{$_SESSION[id]}/{$newfile}.jpg"; if(is_dir($old_file)){ $rename = rename($old_file, $new_file); if(!$rename){ print "something funky is going on"; } }else{ print "$old_file is not a valid directory"; } Quote Link to comment Share on other sites More sharing options...
finestice Posted July 19, 2011 Author Share Posted July 19, 2011 thanks for your fast reply people iv ran that code and it comes up with /members/1/123abc123.jpg is not a valid directory Quote Link to comment Share on other sites More sharing options...
finestice Posted July 19, 2011 Author Share Posted July 19, 2011 how would i find the full path of that file? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 use realpath Quote Link to comment Share on other sites More sharing options...
finestice Posted July 19, 2011 Author Share Posted July 19, 2011 yhh iv found the absolute path which is /home/stigros1/public_html/tyrehq.com/members/1/ and iv change the code to $pid = mysql_insert_id(); $newfile = $pid; $old_file = "/home/stigros1/public_html/tyrehq.com/members/{$_SESSION[id]}/123abc123.jpg"; $new_file = "/home/stigros1/public_html/tyrehq.com/members/{$_SESSION[id]}/{$newfile}.jpg"; if(is_dir($old_file)){ rename($old_file, $new_file); }else{ print "$old_file is not a valid directory"; } STILL NO JOY THOU how do i make the path http://tyrehq.com/members/1/$oldfile.jpg 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.