Warptweet Posted January 4, 2007 Share Posted January 4, 2007 Heres a bit different of a problem I have now...How can I rename a file EXTENSION??? Can somebody help?I think it has to do with...[code]<?phprename("XXX","XXX")?>[/code]Except I don't know what the stuff inside the ""'s do.Can somebody explain to me how I would not rename a file, but change it from a .swf file to a .txt file, while keeping the same name besides the extension change?And after that, I need to write these variables...$flashname = $_POST['flashname']$flashauthor = $_POST['flashauthor']$flashdescription = $_POST['flashdescription']I think I know how to write those variables myself though. I mainly need help with the extension changing, thanks! Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/ Share on other sites More sharing options...
448191 Posted January 4, 2007 Share Posted January 4, 2007 Extensions are just part of the filename:[code]<?phprename('file.oldextension', 'file.newextension');?>[/code]So you ARE in fact renaming the file. Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/#findComment-152802 Share on other sites More sharing options...
Warptweet Posted January 4, 2007 Author Share Posted January 4, 2007 Could you tell me how I would change the extension of the file called $ourFileName, and then change $ourFileName to .txt? Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/#findComment-152803 Share on other sites More sharing options...
448191 Posted January 4, 2007 Share Posted January 4, 2007 Change file with any extension to .txt:[code]<?phprename($fileName, substr($fileName, 0, strrpos($fileName,'.')).'.txt');?>[/code] Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/#findComment-152805 Share on other sites More sharing options...
Warptweet Posted January 4, 2007 Author Share Posted January 4, 2007 Thanks.I have one more question....When I write to a file, can I use a variable this way?[code]$stringData = "$flashname"; fwrite($fh, $stringData);[/code]As you can see, I used $stringData = "$flashname";, is that possible to use? Or will I get an error? If I can't how can I make $stringData = $flashname? Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/#findComment-152809 Share on other sites More sharing options...
448191 Posted January 4, 2007 Share Posted January 4, 2007 Remove the quotes around $flashname. Quotes are used on strings, not variables. Link to comment https://forums.phpfreaks.com/topic/32815-solved-renaming-a-file-extension/#findComment-152814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.