Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/64588-exec-a-commandline-program/
Share on other sites

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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.