HaLo2FrEeEk Posted August 13, 2007 Share Posted August 13, 2007 Ok, I have an image manipulation program that is run from commandline, I have never used exec before and I'm scared to becuase I don't want to mess up my server or anything. Basically, I want people to be able to upload an image, then arrange for some manipulations to take place on the file in a temporary batch file, then use exec to run the program directly from the server. The program is called nconvert.exe, and the main thing I want to do is convert DDS textures into BMP files, the command, from Windows "cmd" is: nconvert -out bmp %1 %1 being the dds file to be manipulated. How would I go about doing the exec part? I know how to do the upload, but not the exec. Can anyone help? Thanks. PS. nconvert.exe will be in the same directory as the upload page. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/ Share on other sites More sharing options...
trq Posted August 13, 2007 Share Posted August 13, 2007 <?php $f = 'filename.dds'; exec("nconvert -out bmp $f"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-322025 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 13, 2007 Author Share Posted August 13, 2007 Ok, so if I were doing this to an uploaded file that I did NOT want stored on my server, could I do this (inside the checks for upload_err, of course): <?php $f = $_FILES['imagefile']['tmpname']; exec("nconvert -out bmp $f"); ?> Or should I use passthru to make it immediately prompt to download the file? Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-322046 Share on other sites More sharing options...
trq Posted August 13, 2007 Share Posted August 13, 2007 That is one of passthru's intended uses yes. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-322048 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 13, 2007 Author Share Posted August 13, 2007 Ok, so now that I know that this should work, I'm gonna test it. Wish me luck and thank you for your help. If it works I'll come back and mark this as solved. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-322079 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 13, 2007 Author Share Posted August 13, 2007 Hmm, no go. Here's the code I'm using: switch ($_FILES['userfile']['error']) { case 0: $ext = strtolower(substr($_FILES['userfile']['name'], strrpos($_FILES['userfile']['name'], '.')+1, strlen($_FILES['userfile']['name']))); if($ext != "dds") { echo "You must upload only DDS textures<br /><br />"; die(include($_SERVER['DOCUMENT_ROOT'].'/footer.php')); } if(is_uploaded_file($_FILES['userfile']['tmp_name'])) { $f = $_FILES['userfile']['tmp_name']; passthru("nconvert -out bmp $f"); } else { echo "File upload failed."; } break; It's not returning anything, no text, no file download dialog, nothing. I don't know what wrong with it, I tried putting the exec command in an if to see if it worked: if(passthru("nconvert -out bmp $f")) { echo "success"; } else { echo "Fail"; } Nothing. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-322093 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 14, 2007 Author Share Posted August 14, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-323214 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 15, 2007 Author Share Posted August 15, 2007 Uhm, bump. I still need help with this. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-324397 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 16, 2007 Author Share Posted August 16, 2007 BUMP! God. Quote Link to comment https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/#findComment-325440 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.