xpace Posted August 21, 2007 Share Posted August 21, 2007 Hi guys, I have quite a lot of jpg images that are actually without extension . Is there any way to add this "jpg" extension using php ??? thank you Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/ Share on other sites More sharing options...
dhruvasagar Posted August 21, 2007 Share Posted August 21, 2007 Well I don't know about that, but I can tell you one thing, it's a simple task you want to do...consider making a simple batch file / bash script for it instead, that will be easier way to do it, unless there's some specific reason behind doing it from php... Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-329694 Share on other sites More sharing options...
vijayfreaks Posted August 21, 2007 Share Posted August 21, 2007 Hi.. If its open then try to open with imagefunction and save as it with the function.. or try to add extension directly.. Regards, Vijay Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-329698 Share on other sites More sharing options...
xpace Posted August 21, 2007 Author Share Posted August 21, 2007 thanks guys, dhruvasagar -> if you know how to create the bash file, I would appreciate it, I don't really care what way it is going to be done, I just thought that PHP would handle such a task and I'm pretty familiar with PHP that's why I was asking about PHP. Vijay -> if I had few pictures I would do it manually, but I have more than 200 of them and that's too much. I'm not sure what you mean by using imagefunction. thanks Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-329763 Share on other sites More sharing options...
xpace Posted August 22, 2007 Author Share Posted August 22, 2007 anyone else have any suggestions please Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-330734 Share on other sites More sharing options...
xyn Posted August 22, 2007 Share Posted August 22, 2007 well i would try using rename() http://php.net/rename rename('old_file', 'new_file_name.jpg'); Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-330735 Share on other sites More sharing options...
chocopi Posted August 22, 2007 Share Posted August 22, 2007 yea rename should work, but then again it might not seeing as it will turn a non-image into a image Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-330776 Share on other sites More sharing options...
xyn Posted August 22, 2007 Share Posted August 22, 2007 i guess; but i though it was just adding an extention to an image file? Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-330798 Share on other sites More sharing options...
xpace Posted August 25, 2007 Author Share Posted August 25, 2007 anyone else please ? I have tried rename already but it doesn't want to add the extension as it looks only for the name itself not the extension (that's what I think) nothing happened after rename with my files, thank you Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-333809 Share on other sites More sharing options...
xpace Posted August 25, 2007 Author Share Posted August 25, 2007 I have solved the problem - here it is > <?php $mydir = dir('imgs'); while(($file = $mydir->read()) !== false) { if(is_dir($mydir->path.$file)) { echo "Directory: ".$file."<BR>"; } else { $new = "image/".$file.".jpg"; echo $file." = ".$new."<br>"; rename($mydir->path."/".$file, $new); } } $mydir->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/65947-solved-how-to-add-an-extension-to-a-file-that-is-without-extension/#findComment-333861 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.