I have a book where is a sample for creating a whole new picture, from a random picture given by the user, and I think there is something wrong in the example, at least I can't use it. The error code gave back by the PHP in the browser:
Fatal error: Uncaught Error: Call to undefined function imagecreatefromstring() in C:\xampp\htdocs\kepkonvertalas.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\kepkonvertalas.php on line 13
The HTML form:
<form action="kepkonvertalas.php" method="post" enctype="multipart/form-data">
<input type="file" name="kep"><br>
<input type="submit" value="kuldes">
</form>
The PHP part:
<?php
$fajl = $_FILES['kep']['tmp_name'];
$kep = file_get_contents($fajl);
$forraskep = imagecreatefromstring($kep);
$szelesseg = imageSX($forraskep);
$magassag = imageSY($forraskep);
$ujmagassag = 400;
$ujszelesseg = $ujmagassag*($szelesseg/$magassag);
$ujkep = imagecreatetruecolor($ujszelesseg, $ujmagassag);
$eredmeny = imagecopyresampled($ujkep, $forraskep, 0, 0, 0, 0, $ujszelesseg, $ujmagassag, $szelesseg, $magassag);
imagejpeg($ujkep, "ujkep.jpg");
?>
<img src="ujkep.jpg" alt="">`
What is suspect, is that this extension is not implemented into my php.ini, but I cant find any proof for it, either solve the problem. Thanks for the help!
I tried to implement a picture from an URL, and do the conversion on that, which means I deleted the
$fajl = $_FILES['kep']['tmp_name'];
$kep = file_get_contents($fajl);`
And I've made a variable with a picture URL, and in the
$forraskep = imagecreatefromstring($kep);
I just changed like this:
$forraskep = imagecreatefromstring(file_get_contents($src);
Well the next problem was, that the $forraskep variable was not defined.
I expect an output where I have the picture with the size of the given parameters.
The solution was actually kinda easy:
open php.ini
search for "extension=gd"
delete the semicolon
restart apache server
Related
I am having an error in my PHP code and I need help. If anyone knows the solution to this issue, please help me. The error message I am seeing is
[Fatal error: Uncaught BadMethodCallException: Method createtemplate is not defined. in C:\xampp\htdocs\php\vendor\phpoffice\phpword\src\PhpWord\PhpWord.php:148 Stack trace: #0 C:\xampp\htdocs\php\index1.php(10): PhpOffice\PhpWord\PhpWord->__call('createtemplate', Array) #1 {main} thrown in C:\xampp\htdocs\php\vendor\phpoffice\phpword\src\PhpWord\PhpWord.php on line 148].
This is my code
<!-- HTML form for selecting the Word document to convert -->
<form method="post" enctype="multipart/form-data">
<label for="word-file">Select Word document:</label>
<input type="file" name="word-file" id="word-file">
<input type="submit" value="Convert">
</form>
<?php
// Check if the form has been submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the uploaded Word document
$wordFile = $_FILES['word-file']['tmp_name'];
// Include the PHPWord library
require_once 'vendor/autoload.php';
// Create a new PHPWord object
$PHPWord = new \PhpOffice\PhpWord\PhpWord();
// Load the Word document
$document = $PHPWord->loadTemplate($wordFile);
// Save the document as a PDF
$document->saveAs('converted.pdf');
// Show a message to the user
echo '<p>The Word document has been converted to PDF.</p>';
}
?>
have tried many solutions but nothing works....
I think you can use save method not to loadTemplate...
please replace your code...
From:
$document = $PHPWord->loadTemplate($wordFile);
$document->saveAs('converted.pdf');
To:
$document = $PHPWord->save($wordFile);
Through the log error, I think you didn't clarify method createtemplate in your PhpOffice\PhpWord\PhpWord.php file!
So it should be worked if you declare that method!
I try using cloudinary for upload my image and video for my personal blog but it's a fail. I watch this video tutorial https://www.youtube.com/watch?v=oZCQLjfq97o. the error says :
Notice: Undefined index: file in >C:\xampp7\htdocs\lovantoBlog\cloudinary\index.php on line 8
Notice: Undefined index: file in >C:\xampp7\htdocs\lovantoBlog\cloudinary\index.php on line 9
Fatal error: Uncaught Cloudinary\Error: Missing required parameter - file in C:\xampp7\htdocs\lovantoBlog\cloudinary\vendor\cloudinary\cloudinary_php\src\Uploader.php:558 Stack trace: #0 C:\xampp7\htdocs\lovantoBlog\cloudinary\vendor\cloudinary\cloudinary_php\src\Uploader.php(407): Cloudinary\Uploader::call_api('upload', Array, Array, NULL) #1 C:\xampp7\htdocs\lovantoBlog\cloudinary\vendor\cloudinary\cloudinary_php\src\Uploader.php(100): Cloudinary\Uploader::call_cacheable_api('upload', Array, Array, NULL) #2 C:\xampp7\htdocs\lovantoBlog\cloudinary\index.php(11): Cloudinary\Uploader::upload(NULL, Array) #3 {main} thrown in C:\xampp7\htdocs\lovantoBlog\cloudinary\vendor\cloudinary\cloudinary_php\src\Uploader.php on line 558
This is my code for upload :
require 'vendor/autoload.php';
require 'config.php';
if (isset($_POST['Simpan'])) {
$nama = $_POST['nama'];
$slug = $_POST['slug'];
$gambar = $_FILES['file']['name'];
$file_tmp = $_FILES['file']['tmp_name'];
\Cloudinary\Uploader::upload($file_tmp, array('public_id' => $slug));
}
and this is the code for form :
<form method="POST">
<input type="text" name="nama">
<input type="text" name="slug">
<?php echo cl_image_upload_tag('image_id');?>
<input type="submit" name="Simpan" value="Simpan">
</form>
The cl_image_upload_tag is used to perform direct uploading from the browser to Cloudinary. When you submit the form you there is no file parameter sent to your backend and thus the Cloudinary::Uploader::upload call fails with the error Missing required parameter - file.
If you would like to upload the file from your backend then you need to replace the cl_image_upload_tag with a regular file input field element. Once a file is selected and the form submitted your backend can use the same code to upload the file to Cloudinary.
On the other hand, if would like to use cl_image_upload_tag then please see the direct uploading section of the Cloudinary documentation that describes setting this up.
https://cloudinary.com/documentation/php_image_and_video_upload#direct_upload_file_tag
I'm programming a simple password checker with a html form, where you input the code and this code is compared as hash to another hashed code in the database. If the password matches, the index.php file shows a few divs, which otherwise are completely hidden from the user.
I've tried things like:
$input = "";
<center>
<form action="" method="GET">
CODE:<br>
<input type="text" name="code" value="">
<br><br>
<input type="submit" value="Submit">
</form>
</center>
<?php
$checker = new Checker();
$input = $_GET['code'];
//echo "<style>.Main_Content{ visibility:hidden;}</style>";
if ($checker->compareWords($input, 'Beginners')) {
echo "success Beginners<br>";
include 'Beginners_Video.php';
echo "<style>.Main_Content{ visibility:show;}</style>";
}
else {
echo "false Beginners<br>";
}
?>
Fatal error: Uncaught TypeError: Argument 1 passed to
Checker::compareWords() must be of the type string, null given, called
in D:\www\www91\members\members.php on line 64 and defined in
D:\www\www91\members\checker.php:23 Stack trace: #0
D:\www\www91\members\members.php(64): Checker->compareWords(NULL,
'Beginners') #1 {main} thrown in D:\www\www91\members\checker.php on
line 23
The result should be no error and just the whole thing hidden, or the output "False Beginners. Nothing else"
I know that i'm just stupid and that the answer is probably really simple. I've tried and I can't figure it out.
Thanks for your help.
Your code should work once you filled in and submitted the form, but there is no check handling the case where $_GET['code'] is unset or empty. Change your if statement to
if (!empty($input) && $checker->compareWords($input, 'Beginners')) {
in order to check for this first. If !empty($input) is false, the next condition won't be checked at all, so there won't be an error message and it will jump to the else clause directly.
On a side note: You should think about whether GET is the right method for what you're trying to achieve or whether POST would be better. With GET, The codes users enter might get saved in the browser's history and be visible to others using the same computer. Also, for passwords use type="password" for the input instead of displaying it in cleartext.
And one more thing: the <center> tag is deprecated and you should use CSS instead for layout.
At the very beginning you should check if something is passed in code parameter, using the isset() method. If $_GET['code'] is empty it will return null and this is why you get must be of the type string, null given.
<?php
if(isset($_GET['code']) {
$input = $_GET['code'];
} else {
// 'code' parameter is empty
$input = '';
}
$checker = new Checker();
// ...
I wrote a simple php script that basically echos the values put into a form on the page, later, I will have this write to a DB but I was working on troubleshooting it before I did that since I keep getting this warning.
Does anyone know why I am getting it? If I just fill in the fields and submit the form, the script works fine and the warning disappears.
PHP Function:
function quickEntry()
{
$subTitle = $_POST['subTitle'];
$subDetails = $_POST['details']; //This is line 13 in my code
echo "$subTitle";
echo "<br>$subDetails";
}
HTML / PHP Code:
<form method="post" action="">
<hr>
<h1>Quick Entry:<p></h1>
Subject Title:<br> <input type="text" name="subTitle"><br><br>
Subject Details: <p><textarea name="details" placeholder="Enter Details here..."></textarea><p><br>
<input type="submit" name="QuickEntrySubmit" value="Submit Quick Entry" /><br>
</form>
<?php
if (isset($_POST['QuickEntrySubmit']))
{
quickEntry();
}
?>
I know that I could disable warnings and I wouldn't see this, but I really just want to know why php is throwing the warning so I can fix the syntax appropriately and keep my code clean going forward. Full warning is:
Notice: Undefined index: details in C:\xampp\htdocs\test1.php on line 13
Thanks!
The reason why you are getting that error is because you are not checking whether the 'subTitle' and 'details' inputs have values in them.
Your code should work well like this:
function quickEntry(){
$subTitle = isset($_POST['subTitle'])? $_POST['subTitle']: null;
$subDetails = isset($_POST['details'])? $_POST['details']: null ; //This is line 13 in my code
if(!is_null($subTitle) && !is_null($subDetails)){
echo "$subTitle";
echo "<br>$subDetails";
} else{
//blah blah blah
}
You get the warnings because the $_POST variables with the indexes that you're checking for ($_POST['subTitle'] & $_POST['details']) aren't set, so the variables are empty as you reference something that isn't there.
You should do a check to ensure they are set first before trying to assign them to a variable:
$subTitle = (isset($_POST['subTitle']) && !empty($_POST['subTitle'])) ? $_POST['subTitle'] : null;
$subDetails = (isset($_POST['details']) && !empty($_POST['details'])) ? $_POST['details'] : null;
The above code will check to ensure the post index isset() and isn't empty() before assigning it to the variables.
NOTE
The variables are set when you submit the form because you are actually posting the data to the script.
You see the input attribute name? When you submit the form, they are the relevant $_POST indexes.
Just remember to ensure that the values aren't empty if you intend to print them to the markup.
I'm really new to PHP and Im trying to append Nodes to XML using PHP.
This is my comments.php file:
<?php
$date = "http://jdrag.x10.mx/comments_file.xml";
$xml = simplexml_load_string($data);
$commentt = $xml->addChild("comment");
$name = $_POST["cname"];
$email = $_POST["cemail"];
$comment = $_POST["comment"];
$commentt->addChild("name", $name);
$commentt->addChild("email", $email);
$commentt->addChild("commentInside", $comment);
echo $xml->saveXML();
?>
My comments.html is:
<form action="comments.php" method="post">
Name: <input type="text" name="cname" />
Email: <input type="text" name="cemail" />
Comment: <input type="text" name="comment" />
<input type="submit" />
</form>
As you can see my XML file is simple the comments tag: http://jdrag.x10.mx/comments_file.xml
But when I submit the form I get this error:
Fatal error: Call to a member function addChild() on a non-object in /home/jdragx10/public_html/comments.php on line 5
And because i'm new to PHP I really don't know what it means or how to fix it.
Thanks in advance to anyone who can fix my code.
It looks like you want to be using simplexml_load_file().
The simplexml_load_string() function takes the XML document as a string whereas simplexml_load_file() takes the path to a file containing the XML, as you have.
You also have some problem with variable names, the path to the XML file is held in $date whereas you try to load the XML using the variable $data.
Finally, be sure to turn on (and to the maximum level) error reporting while you are writing your code. The code above gives a notice message ("Notice: Undefined variable: data…"), not just a fatal error message.
Set the values display_errors and error_reporting to On and -1 respectively, either in your php.ini file or using ini_set().