<?php /* Redirect to a different page in the current directory that was requested */ $mime = "application/x-httpd-php"; $user = $_POST['username']; $filename = "".$user.".php "; $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = $filename; $result = $_POST['code']; $filehandle = fopen($filename, 'w') or die("We have failed to open your file"); fwrite ($filehandle, $result); chmod("$filename", 0777); ?> PHP: Now, this creates a file depending on your input. (eg, if you input "hello" it creates the file "hello.php"), however, it is supposed to be a PHP application, but the MIME type is just plain text, and when I try to go to it, I get error 404. So how can I change the MIME type to the value of $mime Thanks, BP
PHP = Plain text, the MIME type is just right. And even if it wasn't, you cannot change it. The MIME type is not saved within the file, the browser (or whatever app you're using) decides what MIME type it shows you, based on the extension (or content in some cases). As for the 404, it means there's no such file. It has nothing to do with the MIME type.
Well, the file exists. And PHP files I manually create in cPanel have the type: application/x-httpd-php, but the automatically generated ones are just plain text. Is there any possible way it could be hidden upon generation? Thanks, BP
Is the case you enter in the address bar right? (On Apache files are case-sensitive). Do you have an .htaccess file which could be overwriting rules? Where does it say application/x-httpd-php? Drag this file into another application and you possibly get another MIME type. As said, the file itself does not know its MIME type. And some files can have several valid MIME types. Your problem lays somewhere else. Even if the file type was one that the browser can't read, you would not get an 404 error. EDIT: I think I found your error. $filename = "".$user.".php "; PHP: There's a space after the file name.