Jump to content

saving result of an exe file


bardman6

Recommended Posts

Hello php freaks,

 

I have worked extensively with ASP and SQL, but am a php newbie. I recently started a new job and some of the sites I inherited are php.

 

Okay now to my question. I have a site that does a good job of pulling images discretely so that it is very hard for anyone to see where they are on the server. It uses a "getimage.exe" file with query strings so that you can view the image (or pdf, or doc, or whatever the file may be, and it could be a multitude of types). However, it makes it difficult if someone wants to save it, so my assignment was to have an option to save the image in the tool bar in a zip file. I have worked out the zip part of it, but the problem is that I can't get the image to save to a directory. I can't edit getimage.exe and am getting an error using the query string results. I understand that the query strings are throwing the error, but I am not sure what else to do. Is there a way to save the file resulting from getimage.exe to the save folder? And also i am not sure how to get $imagename, which will be an image, pdf, or whatever.

 

Any ideas?

 

here is the code so far:

 

<?php

 

$alias = $_GET['ROOT'];

$itnum = $_GET['ID'];

$directoryToZip="temp/"; // This will zip all the file(s) in this present working directory

 

$outputDir="temp/";

 

// this is where the error is Warning: copy(getimage.exe?CISOROOT=/achieve&CISOPTR=700) [function.copy]: failed to open stream: Invalid argument

copy("getimage.exe?CISOROOT=".$alias."&CISOPTR=".$itnum , "temp/".$imagename);

 

 

//from here down works.

$zipName=".zip";

 

include_once("CreateZipFile.inc.php");

$createZipFile=new CreateZipFile;

 

 

 

//Code toZip a directory and all its files/subdirectories

$createZipFile->zipDirectory($directoryToZip,$outputDir);

 

$zipName=time().$zipName;

$fd=fopen($zipName, "wb");

$out=fwrite($fd,$createZipFile->getZippedfile());

fclose($fd);

$createZipFile->forceDownload($zipName);

@unlink($zipName);

//echo ($zipName);

 

//rename("temp/getimge.exe?CISOROOT=".$alias."&CISOPTR=".$itnum , "getimge.exe?CISOROOT=".$alias."&CISOPTR=".$itnum)

?>

 

Thanks in advance.

 

bardman6

 

PS the zip works when i remove the query strings and set the make $imagename into a constant.

 

Link to comment
Share on other sites

// this is where the error is Warning: copy(getimage.exe?CISOROOT=/achieve&CISOPTR=700) [function.copy]: failed to open stream: Invalid argument

copy("getimage.exe?CISOROOT=".$alias."&CISOPTR=".$itnum , "temp/".$imagename);

 

What does getimage.exe actually return? copy expects a path to a file.

 

If I where you I would get rid of this getimage.exe file all together. it doesn't sound like its doing anything that can't be done in php alone.

Link to comment
Share on other sites

If I where you I would get rid of this getimage.exe file all together. it doesn't sound like its doing anything that can't be done in php alone.

 

getimage.exe is something that someone else did. What it does is gets the image, pdf or what ever, on a different server and hides the location. (I honestly do not know why they need it like this, but it is what it is). I do not have direct access to the file. The only way I get to it is through getimage.exe. So I cannot get rid of getimage.exe, unfortunately.

Link to comment
Share on other sites

So... back to my first question.

 

That is a really good question. It gets the image, where ever it is, and allows it to display. Outside of that I have no idea how it works or what else it does because I do not have the source files for getimage.exe. I don't really know what it returns. When I look up images and do the save image as, the default name is getimage.exe.jpg. I don't know if that answers your question or not.

 

BTW, I tried to do a $variable = exec(getimage.exe?blah blah blah) and it didn't work because the IIS server doesn't have exec privileges  :-[

 

The bottom line is that I don't have direct access to the file. It has to go through the getimage.exe. And unfortunately copy() does not handle query strings. If there is a way to do this, I would greatly appreciate it.

 

Link to comment
Share on other sites

I think I have found a solution, based on this: http://stackoverflow.com/questions/724391/save-image-from-php-url-using-php

 

I was going about this the wrong way. Instead if copy(), why not use fopen() and fwrite()? In a few tests so far it has worked, anyone see any problems with this (other than the fact that it is only a jpg, someone in my office says he knows how to fix that)? Thanks for your help!

 

function save_image($inPath,$outPath)

{ //Download images from remote server

    $in=    fopen($inPath, "rb");

    $out=  fopen($outPath, "wb");

    while ($chunk = fread($in,8192))

    {

        fwrite($out, $chunk, 8192);

    }

    fclose($in);

    fclose($out);

}

 

 

//$fileToZip="DMS.jpg";

//$fileToZip1="CreateZipFileMac.inc.php";

//$fileToZip2="CreateZipFile.inc.php";

$alias = $_GET['CISOROOT'];

$itnum = $_GET['CISOPTR'];

 

save_image('http://blahblahblah.com/getimage.exe?CISOROOT='.$alias.'&CISOPTR='.$itnum.'','temp/img.jpg');

Link to comment
Share on other sites

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.