File display using PHP and header() not working [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to show any file in the browser using PHP and headers, but it isn't working with a PNG image, it shows a strange black square like this:
The Strange Blank Square
Here is my code:
<?php
header('Content-Type: ' . mime_content_type($filepath));
readfile($filepath);
die();
?>
I already checked the $filepath variable, its the full path (E:\wwwPublic\myapp\application\controllers\..\..\documents\34807\image.PNG) I don't know what is going wrong in that code.
Do you have any idea(s) ?

I solved it, I found that Code Igniter has default headers, I needed to add ob_clean() to remove all of them and add my own, Thank you for your help

Related

Page crashes with no clue why [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a webpage weblup(dot)net/templates/template3 (replace (dot) with a '.') and it just crashes when I run it. It was working fine not long ago but I have no clue why it's crashing all of a sudden. The biggest change before this happened was that I changed a picture.
Your Website have error in logo.png and it's to big to load in website. (16620 x 9333 pixels).
Solution: Change Your Image and resolution Image

How to reload a page in PHP before exit function? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got some code like this and the header is not working
if ($variable > 0) {
header('Location: mypage.php');
exit;
}
And I need exit function, is this a bad idea?
If your code produces any output text before header directive then header directive will be ignored.
Even if header is located before any output (HTML or PHP), be sure not to have any characters nor spaces between beginning of PHP file and <?php tag.
However, there is a chance that header directive will be accepted even if there is output present before it, if written text is still in the PHP output buffer and nothing has yet been sent to web server. But, to be safe, make header the first thing before any text output.

PHP does not copy the file properly [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
im copying a file from another domain. It does not give me any errors but the files does not get recognized and its different size from the original file. Its the same extension i checked. so im kinda clueless.
if (!copy('http://maholi.com/image/data/Products/Linen - Juvenile and Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/resources/categories/tttt6.jpg')) {
echo "failed";
}
any ideas?
This works fine for me:
if (!copy('http://maholi.com/image/data/Products/Linen%20-%20Juvenile%20and%20Infant/1440.jpg', $_SERVER['DOCUMENT_ROOT'].'/tttt6.jpg')) {
echo "failed";
}
Edit: URL's are not allowed to contain spaces. See "Is a URL allowed to contain a space?". Your web browser will automatically encode illegal characters, making you believe they are allowed.

Coding Help Regarding Meta Tag And Site Title [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Hello Guys I need a small help pls Check this code
print ' File Name: '.translit($file).' Video Song
in this code .translit($file). is name of my file and i want to show this file name in my site page title meta tag and also in meta keywords..
and when i am adding this code into
echo "<title>.translit($file). </title>";
it showing code as it is..
m newbie pls givvme sloution of this
You just need to close the strings before concatenating them ie:
echo "<title>".translit($file)."</title>";

Code for set the url as usernameq [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I use a code to set the URL as:
http://domainname.com/user
The problem is that I use some masks in my .htaccess, so what we see in the URL is not always the real path of the file.
What I need is to get the URL, what is written in the URL, nothing more and nothing less—the full URL.
I need to get how it appears in the Navigation Bar in the web browser, and not the real path of the file on the server.
You need to simple check in PHP what's the value of $_SERVER['REQUEST_URI']
or substr($_SERVER['REQUEST_URI'],1) if you want to remove leading slash

Categories