Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Improve this question
I'm getting this error
( ! ) Warning:
file_get_contents(wp-content/uploads/2013/06/wpid-Mt-ZionlaunchA4poster.jpg<br>)
[function.file-get-contents]:
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in
C:\wamp\www\progjet\3\post.php on line 55
As you can see, there is a <br> tag at the end of the file name.
Here is my code:
foreach($imgf as $imgr){
echo $imgr;
$upimg[] = get_img(trim($imgr));
}
function get_img($url){
file_put_contents(basename($url),file_get_contents($url));
$path = 'http://'. $_SERVER['SERVER_NAME'] . dirname($_SERVER['REQUEST_URI']);
return $path.'/'. basename($url);
}
as you can see I add echo to see the what is going on
and here is the out put
What is the source of $imgf. If it's POST / GET data then you need to remove <br> from POST/GET request page.
If you want to remove the <br> using PHP you can do like this:
$imgr = str_replace('<br>', '', $imgr);
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Hey there i have this snippet:
$profile_pic = imagecreatefromjpeg("upload_Main/".$user[1].".jpg");
This function works (upload_Main: folder:777 ; files:644)
But this snippet:
$profile_pic = imagecreatefromjpeg("upload_Sub/".$user[1].".jpg");
Doesnt work (upload_Sub: folder:777 ; files:644).
They have exactly the same files and the same right´s, so why does the second one not work? Any idea´s? thanks and greetings!
imagecreatefromjpeg():
Returns an image resource identifier on success, FALSE on errors.
I had it return False on an image that was manually re-named to a JPG, when it was actually a PNG.
I got an error saying:
'not a valid JPEG file'
You should look to see what error you get when performing that function, That way you'll know exactly what's goind bad.
One way to check for the error is creating a PHP file next to the image with:
<?php
echo imagecreatefromjpeg("path/to/image");
?>
run it in using 'php filename.php'
and looking in the console for the result
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do I make the following url to be read:
localhost/index.php?errormsg=wrongpassword
so I want it to set the variable $errormsg to 'wrongpassword' how do I do that? I am pretty sure there is a way using $_GET or $_POST?
You want to use $_GET['errormsg'].
Something like this should do:
if isset($_GET['errormsg'])
{
echo $_GET['errormsg'];
}
$errormsg = $_GET['errormsg']
This should do the trick for you
$_GET['errormsg'] is the answer of your question.
print_r($_GET)
to see all variables in the URL. in this case you want
$_GET['errormsg']
You were as close as ever. A single google would've yielded the answer to you :)
http://php.net/manual/en/reserved.variables.get.php
<?php
// use htmlspecialchars() to clean up url-encoded characters
$error_message = htmlspecialchars($_GET["errormsg"]);
echo 'Error: ' . $error_message;
?>
prints: "Error: error_here", if url = ...?errormsg=error_here
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Parse error: syntax error, unexpected T_IS_IDENTICAL in /home/vvcoutur/public_html/wp-content/themes/stoconverge/header.php on line 54
This is line 54:
<?php ======= COOKIE DEMO OPTIONS ======= //wp_enqueue_style('skins', get_template_directory_uri(). '/admin/layouts/' . $data['alt_stylesheet'] ); ?>
What am i getting wrong
======= COOKIE DEMO OPTIONS =======
should be a comment it isn't and your code is commented out. Try this :
<?php /**======= COOKIE DEMO OPTIONS =======**/ wp_enqueue_style('skins', get_template_directory_uri(). '/admin/layouts/' . $data['alt_stylesheet'] ); ?>
With better formatting and using an IDE you would have seen this easily.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a text file on my local server. I want to read content data of this text file and write it into textbox in a html .
Could you please help me?
$data = file_get_contents('yourfile.txt');
echo '<textarea>', htmlspecialchars($data), '</textarea>';
The file_get_contents() loads the data, and then you just need to echo it. Using htmlspecialchars() takes care of escaping any of the data, as needed in the context of HTML.
$textAreaContent = "";
$fp = fopen("read_file.txt", "r");
// If file exist and opened
if($fp)
{
while (($buffer = fgets($fp, 1024)) !== false)
$testAreaContent .= $buffer;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Getting weather data from openweathermap fails. Here is my code:
$xml = new
SimpleXMLElement(file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=london&mode=xml'));
$country = $xml->code->country;
$city = $xml->code->city;
echo "Country: $country<br/>City: $city";
When I echo I don't get anything at all. Help is appreciated!
The proper path to the country and city values are as follows:
$country = $xml->city->country;
$city = $xml->city['name'];
You may also need to remove the spaces in your URL, so the complete code would look like:
$xml = new SimpleXMLElement(file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=london&mode=xml'));
$country = $xml->city->country;
$city = $xml->city['name'];
echo "Country: $country<br/>City: $city";
You may want to have a quick look over basic SimpleXML usage.
You are missing all the error message nor are you missing to check function return values before continuing further on:
Warning: file_get_contents(http://api.openweathermap.org/data/2.5/weather? q=london&mode=xml): failed to open stream: HTTP request failed! HTTP/1.1 400 BAD_REQUEST
This means your HTTP request has failed because it's a bad request. Check if the URI is correct. If so, contact the API service provider for your support options.
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML'
Your script has a fatal error. It not only does not output anything, it even stopped to halt before it reached it's planned end. That is because you think everything must always work. Instead also check for error messages.
This has been outlined in a previous question here:
How to get useful error messages in PHP?