janim Posted August 8, 2007 Share Posted August 8, 2007 i wanna change the name of existing files in upload $checkfilename= "select id from $table where file='".$POST['file']."';"; $qryname=mysql_query($checkfilename) or die ("Could not match data because ".mysql_error()); $num_file= mysql_num_rows($qryname); if ($num_file != 0 ){ $newfilename = "A" . $oldfile ."" ; } else { $newfilename=$oldfile; } but nothing happend it change the file name once when i upload file named index.php for the second time =Aindex.php but after this it's overwrite the existing files any comment thanks Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/ Share on other sites More sharing options...
simcoweb Posted August 8, 2007 Share Posted August 8, 2007 One thing right off the bat: $checkfilename= "select id from $table where file='".$POST['file']."';"; Take off the last "; You duplicated it. Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318865 Share on other sites More sharing options...
lemmin Posted August 8, 2007 Share Posted August 8, 2007 When you DO get it to change the file name, do you update the 'file' field in your database? If you don't, $num_file will be 0 and it won't change the $newfilename string. Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318868 Share on other sites More sharing options...
janim Posted August 8, 2007 Author Share Posted August 8, 2007 do you update the 'file' field in your database? no in my DB it's store the $oldfile my code was like this if ($num_file != 0 ){ $newfilename = "A" . $oldfile ."" ; } else { $newfilename=$oldfile; } the $oldfile saved in my DB but it's save it again and again Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318875 Share on other sites More sharing options...
janim Posted August 8, 2007 Author Share Posted August 8, 2007 any comments please :o :o :o :o :o :o :o Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318917 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 i dont know wht exactly you mean but when you want to rename the file in the dir i guess use this http://www.php.net/manual/en/function.rename.php or explain moreeeeeee Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318924 Share on other sites More sharing options...
lemmin Posted August 8, 2007 Share Posted August 8, 2007 I think you need to show more code for me to understand exactly what you are doing. From What I can see it seems like you are checking for the original file name, changing it, then looking for the new file name where the old file name is, but I could be wrong because I don't see this code. Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318927 Share on other sites More sharing options...
janim Posted August 8, 2007 Author Share Posted August 8, 2007 do you update the 'file' field in your database? what do you mean by this couse echo $num_file; the result is 0 so i cant see what do you mean by this many thanks Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318933 Share on other sites More sharing options...
janim Posted August 8, 2007 Author Share Posted August 8, 2007 yes that's close i want to upload files in folder called upload so the name of this file stores in DB with file field ok ? the name of file could be similar to another so the sys. gonna overwrite it ok ? i want check from DB in file field if the file is exist or not if yes change this file name to A+original name and so on Quote Link to comment https://forums.phpfreaks.com/topic/63968-is-there-any-wrong-with-my-code-here/#findComment-318941 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.