# is there a way to add RC_DATA resource to a file with php ? :)

Page 1 of 1

## 4 Replies - 475 Views - Last Post: 18 May 2013 - 01:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=321290&amp;s=2839e4555cd999e0c3d4c8ee990b2481&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 theshowtekfan

Reputation: 1
• Posts: 147
• Joined: 27-September 11

# is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 06:28 PM

hi there, i am working on a file protector webpage wich will protect .net files and i am trying to add the bytes of the .net program to the rc_data resources of another file, to do this i would either need access to the win32 api functions or i would need some other way to edit rc_data

please help me out here, i tried googling but did not find anything else than the outdated and not working php_win32.dll

Is This A Good Question/Topic? 0

## Replies To: is there a way to add RC_DATA resource to a file with php ? :)

### #2 Atli

Reputation: 3853
• Posts: 6,356
• Joined: 08-June 10

## Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 07:04 PM

PHP has a number of Windows Extensions, but the Win32 extension is apparently considered dead, like you say. Not sure of a .NET or COM extension is of any use in this?

If not, you could always write a .NET or C++ program to do this, and then execute it through PHP. That way you won't have to be using PHP - which is hardly built for this kind of work - to do the task itself, and can use more "native" methods in a language that fully supports the APIs needed.

### #3 theshowtekfan

Reputation: 1
• Posts: 147
• Joined: 27-September 11

## Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 07:23 PM

well i thought about a backend C++ server, as that i my main language but idk how to make a front end php and backend C++

### #4 Atli

Reputation: 3853
• Posts: 6,356
• Joined: 08-June 10

## Re: is there a way to add RC_DATA resource to a file with php ? :)

Posted 17 May 2013 - 08:03 PM

Well, PHP is never on the front-end. In the context of web development (which it is, 99.9% of the time), PHP is exclusively a server-side language.

I'm not suggesting that you build a PHP-like, server-side web app in C++. Just that you create a C++ program that does whatever it is you want to do with these Windows APIs, and then execute that program from PHP when needed. PHP can still take care of everything relating to creating the website, just using your C++ program as a way to take care of this RC_DATA stuff.

For example, imagine if you created a EXE file in C++ or .NET that did some modifications to a file and saved it as a new file. That you could execute this program in a CMD window like so:
> C:\path\to\my\app\convert.exe "C:\files\input.file" "C:\files\output.file"



You could have PHP do just that, using the exec methods, and then use the result of this EXE. Consider if you allowed your users to upload the input file for this program through PHP, this code would run it through this EXE and feed the modified file back to the user:
<?php
if (isset($_FILES["theFile"]) &&$_FILES["theFile"]["error"] == 0) {
// Define a path where the converted file should be put,
// and get the location of the temporary file created by PHP
$outputFile = "C:\\modified_files\\" .$_FILES["theFile"]["name"];
$inputFile =$_FILES["theFile"]["tmpName"];

// Create a shell command that executes an external program
// and passes both file paths to it as parameters.
$command = "C:\\path\\to\\my\\app\\convert.exe \"{$inputFile}\" \"{$outputFile}\""; // Execute the command. PHP will pause at this point, waiting for the // process to finish. exec($command, $output,$result);

// The result will be whatever result the EXE returns.
if ($result == 0) { // Since it was successful, feed the modified file back // to the user. header("Content-type: " .$_FILES["theFile"]["type"]);
header("Content-Disposition: attachment; filename='{$_FILES["theFile"]["name"]}'"); header("Conent-Length: " . filesize($outputFile));
readfile($outputFile); exit; } else { echo "Failed to convert your file."; } } else { echo "Upload a file, genius."; }  Of course, I've done very little input validation here, so this is not exactly a safe script, but you get what I mean. PHP doesn't have to do all the actual work itself, it can rely on programs written in other language to do things it lacks the APIs to do itself. Was This Post Helpful? 0 ### #5 theshowtekfan • D.I.C Head Reputation: 1 • Posts: 147 • Joined: 27-September 11 ## Re: is there a way to add RC_DATA resource to a file with php ? :) Posted 18 May 2013 - 01:28 PM Atli, on 17 May 2013 - 08:03 PM, said: Well, PHP is never on the front-end. In the context of web development (which it is, 99.9% of the time), PHP is exclusively a server-side language. I'm not suggesting that you build a PHP-like, server-side web app in C++. Just that you create a C++ program that does whatever it is you want to do with these Windows APIs, and then execute that program from PHP when needed. PHP can still take care of everything relating to creating the website, just using your C++ program as a way to take care of this RC_DATA stuff. For example, imagine if you created a EXE file in C++ or .NET that did some modifications to a file and saved it as a new file. That you could execute this program in a CMD window like so: > C:\path\to\my\app\convert.exe "C:\files\input.file" "C:\files\output.file"  You could have PHP do just that, using the exec methods, and then use the result of this EXE. Consider if you allowed your users to upload the input file for this program through PHP, this code would run it through this EXE and feed the modified file back to the user: <?php if (isset($_FILES["theFile"]) && $_FILES["theFile"]["error"] == 0) { // Define a path where the converted file should be put, // and get the location of the temporary file created by PHP // for the file upload.$outputFile = "C:\\modified_files\\" . $_FILES["theFile"]["name"];$inputFile = $_FILES["theFile"]["tmpName"]; // Create a shell command that executes an external program // and passes both file paths to it as parameters.$command = "C:\\path\\to\\my\\app\\convert.exe \"{$inputFile}\" \"{$outputFile}\"";

// Execute the command. PHP will pause at this point, waiting for the
// process to finish.
exec($command,$output, $result); // The result will be whatever result the EXE returns. if ($result == 0) {
// Since it was successful, feed the modified file back
// to the user.
header("Content-type: " . $_FILES["theFile"]["type"]); header("Content-Disposition: attachment; filename='{$_FILES["theFile"]["name"]}'");
header("Conent-Length: " . filesize($outputFile)); readfile($outputFile);
exit;
}
else {
echo "Failed to convert your file.";
}
}
else {