I'm trying upload a file using zend form. I've tried in so many ways but i'm getting the form post data with file name but file was not receiving. Here is my code
**My Form code**
public function testUploadForm(){
$imageviewScript = new Zend_Form_Decorator_ViewScript();
$imageviewScript->setViewScript('image_element.phtml');
$image_name = new Zend_Form_Element_File('image_name');
$image_name->setAttrib('enctype', 'multipart/form-data');
$image_name->addValidator('Extension',false,'jpg,png,gif');
$image_name->addValidator('Count', false, 1)
//$image_name->setRequired(true)
->addDecorator($imageviewScript)
->setDecorators($this->setFieldElementDecorators());
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Submit')
->setAttrib('class', 'addbutton_6')
->removeDecorator('label')
->setDecorators($this->getRightSubmitDecorators());
$this->addElements(array($image_name,$submit));
}
In controller i'm using to receive data like
public function testuploadAction(){
$params= array();
$this->_form->testUploadForm();
if($this->getRequest()->isPost()){
$params= $this->getRequest()->getParams();
$upload= new Zend_File_Transfer_Adapter_Http();
$upload->setDestination(APPLICATION_PATH.'/../images/uploads/');
if($uploads->receive()) {
//Code to process the file goes here
$filesize = $upload->getFileSize('image_name');
print_r($file_size);exit;
} else {
$errors = $upload->getErrors();
}
//$formData = $_POST->getValues(); //be sure to call this after receive()
print_r($formData);exit;
//$file = $upload->getFileInfo();
// $filename = $upload->getFileName('image_name'); //optional info about uploaded file
}
$this->_form->populate($params);
$this->view->form= $this->_form;
}
when I tried to print the data it was showing warnings like below.
Notice: Undefined index: validators in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493
Warning: array_search() expects parameter 2 to be array, null given in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 493
Notice: Undefined index: tmp_name in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 589
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\XXXX\library\Zend\Validate\File\Count.php on line 228
No Syntax errors nothing. Form was submitting properly but file was not receiving here.
I've changed the file element to Zend file element i'm getting below fatal error after submitting the form.
Fatal error: Uncaught exception 'Zend_File_Transfer_Exception' with message '"image_name" not found by file transfer adapter' in C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php:1254 Stack trace: #0 C:\xampp\htdocs\XXXX\library\Zend\File\Transfer\Adapter\Abstract.php(572): Zend_File_Transfer_Adapter_Abstract->_getFiles('image_name') #1 C:\xampp\htdocs\XXXX\library\Zend\Form\Element\File.php(435): Zend_File_Transfer_Adapter_Abstract->isValid('image_name') #2 C:\xampp\htdocs\XXXX\library\Zend\Form.php(1987): Zend_Form_Element_File->isValid('shreyansh-ipad ...', Array) #3 C:\xampp\htdocs\XXXX\application\controllers\CustomerController.php(41): Zend_Form->isValid(Array) #4 C:\xampp\htdocs\XXXX\library\Zend\Controller\Action.php(503): CustomerController->registerAction() #5 C:\xampp\htdocs\XXXX\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action->dispatch('registerAction') #6 C:\xampp\htdocs\XXXXX\library\Zend\Controller\Front.php(934): Zend_Co in C:\xampp\htdocs\XXXXX\library\Zend\File\Transfer\Adapter\Abstract.php on line 1254
Can some one plz suggest why the files are not uploading for me. Thank you.
Finally I found the solution. It is happening due to the form encryption only. To achieve some sort of website design I'm echoing each field in the view file i.e, .phtml file. So there i'm using the normal form. Even I'm assigning the encryption type to zend form, it was not coming in the phtml form, so the file was not uploading now i set like
<form enctype="multipart/form-data" method="post" action="" >
Now it is working fine. Thanks
Related
I want to create a database diagram using php jawira/db-draw library (https://jawira.github.io/db-draw/index.html) for this.
Without using SQL queries everything works great, but when I want to use a query it displays an error.
Fatal error: Uncaught TypeError: Jawira\DbDraw\DbDraw::__construct(): Argument #1 ($connection) must be of type Doctrine\DBAL\Connection, Doctrine\DBAL\Driver\PDO\Statement given, called in C:\xampp\htdocs\diagram\index.php on line 18 and defined in C:\xampp\htdocs\diagram\vendor\jawira\db-draw\src\DbDraw.php:26 Stack trace: #0 C:\xampp\htdocs\diagram\index.php(18): Jawira\DbDraw\DbDraw->__construct(Object(Doctrine\DBAL\Driver\PDO\Statement)) #1 {main} thrown in C:\xampp\htdocs\diagram\vendor\jawira\db-draw\src\DbDraw.php on line 26
Code below:
require_once __DIR__.'/vendor/autoload.php';
use Doctrine\DBAL\DriverManager;
use Jawira\DbDraw\{DbDraw, Theme};
use Jawira\PlantUmlClient\{Client, Format};
// a. Some logic to retrieve $connection (\Doctrine\DBAL\Connection)
$connectionParams = ['url' => 'mysql://root:#127.0.0.1/baza_testowa',
'driver' => 'pdo_mysql'];
$connection = DriverManager::getConnection($connectionParams);
$sql = 'SELECT * FROM czlowiek';
$stmt = $connection->query($sql);
//b. Generating PlantUML diagram
$dbDiagram = new DbDraw($stmt);
$puml = $dbDiagram->generatePuml(DbDraw::MAXI, Theme::AMIGA);
file_put_contents('database.puml', $puml);
// c. Converting & saving png image
$client = new Client();
$png = $client->generateImage($puml, Format::PNG);
file_put_contents('database.png', $png);
$url = $client->generateUrl($puml, Format::PNG);
echo "<img src='$url'>";
Probably on the line:
$dbDiagram = new DbDraw($stmt);
There is a value written in parentheses. But the documentation is poor, so I don't know exactly what to put there. When I type $connection there it displays a diagram skipping the SQL query.
Please help.
I like to use the list on this page: list of teams of soccerclub
But I always get this error
Fatal error: Uncaught Error: Call to a member function find() on null in /home/u562375926/domains/lucswebsite.tech/public_html/resp/scrapvv.php:152 Stack trace: #0 {main} thrown in /home/u562375926/domains/lucswebsite.tech/public_html/resp/scrapvv.php on line 152
using this code:
<?php
include('simple_html_dom.php');
$file = 'https://www.voetbalvlaanderen.be/club/1771/ploegen';
$html = new simple_html_dom();
$html->load_file($file);
$club = $html->find('div',8)->find(h2);
echo $club. '<br>';
?>
I have used the same page in ParseHub and I get all a hrefs and the text of the corresponding spans.
Is it possible that DOM is not working on that page?
trying to get every post and comment from a facebook page, I made this function that should go through the pagination:
$req = $facebook->api("/" . $pagename . "/?fields=posts.fields(message,link,created_time,shares,likes,comments)");
function parcours_arbre($ab)
{
GLOBAL $facebook;
GLOBAL $pagename;
$next = create_request($ab['posts']['paging']['next']);
$next_req = $facebook->api($pagename.$next);
$ab_next = $next_req['data'];
$prev = create_request($ab['posts']['paging']['previous']);
$prev_req = $facebook->api($prev);
$ab_prev = $prev_req['data'];
if (empty($ab)) {
display_results($ab['posts']['data']);
} else {
parcours_arbre($ab_next);
parcours_arbre($ab_prev);
}
}
I unfortunately get the following error:
Notice: Undefined index: posts in /form.php on line 36
Notice: Undefined offset: 3 in /utils.php on line 20
Notice: Undefined offset: 4 in /utils.php on line 20
Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in /sdk/src/base_facebook.php on line 1271
Any idea how i could avoid it or what is going on? Would this go away if i use the "until" statement in my api request?
Thanks a lot,
To explain each error
the variable $ab which is an argument to the function, does not have a "posts" index. You should try to var_dump this variable so you can see what it actually looks like.
same as above
same as above
the api function takes 3. The path which should just be #pagename. The method ("GET" or "POST") most likely POST because GET is causing an error. The parameters, which should be array("fields" => "posts.fields(message,link,created_time,shares,likes,comments)")
I noticed that for next you have the code
$next_req = $facebook->api($pagename.$next);
but for previous you have
$prev_req = $facebook->api($prev);
Might want to look into this.
I want to implement Strip payment process in a site. I tried to do it but it's not look working. The error I got is
Fatal error: Uncaught exception 'Stripe_InvalidRequestError' with message 'Could not determine which URL to request: Stripe_Charge instance has invalid ID: ' in /home/twassist/public_html/wp-content/themes/inovado/stripe-php-1.7.15/lib/Stripe/ApiResource.php:46 Stack trace: #0 /home/twassist/public_html/wp-content/themes/inovado/stripe-php-1.7.15/lib/Stripe/ApiResource.php(15): Stripe_ApiResource->instanceUrl() #1 /home/twassist/public_html/wp-content/themes/inovado/stripe-php-1.7.15/lib/Stripe/ApiResource.php(8): Stripe_ApiResource->refresh() #2 /home/twassist/public_html/wp-content/themes/inovado/stripe-php-1.7.15/lib/Stripe/Charge.php(14): Stripe_ApiResource::_scopedRetrieve('Stripe_Charge', NULL, NULL) #3 /home/twassist/public_html/wp-content/themes/inovado/functions.php(355): Stripe_Charge::retrieve(NULL) #4 /home/twassist/public_html/wp-content/themes/inovado/functions.php(361): Strip_Code() #5 /home/twassist/public_html/wp-settings.php(291): include('/home/twassist/...') #6 /home/twassist/public_html/wp-config.php( in /home/twassist/public_html/wp-content/themes/inovado/stripe-php-1.7.15/lib/Stripe/ApiResource.php on line 46
Do someone tried it here http://twassistant.com/hire change the quantity.
Fill this detail 5555 5555 5555 4444 expiry date 12 / 21 name: anything 121.
This will make test payment. When come redirect to the code it's give you this error.
Here is the code I tried in my php file.
function Strip_Code()
{
$stripCode = trim($_GET['stripeToken']);
if (strlen($stripCode) > 0) {
require_once dirname(__FILE__).'/stripe-php-1.7.15/lib/Stripe.php';
Stripe::setApiKey("sk_test_XXXXXXXXXXXXXXX");
$resp = Stripe_Charge::retrieve($$stripCode);
var_dump($resp);
}
}
Strip_Code();
could be that you have a typo (double $$):
Stripe_Charge::retrieve($$stripCode);
also, you shouldn't reveal your private key... even if it's just your test key
I am using DOMDocument to parse an XML file. I loop through the different Elements and see if any of them is missing and I fill an array with a createElement, with the error message. At the end I'm trying to appendChild that array but I always get the same error message:
Uncaught exception 'DOMException' with message 'Wrong Document Error'
DOMNode->appendChild(Object(DOMElement))
1 {main}
thrown in /xxx/xxx.php on line 235
PHP Fatal error: Call to undefined method DOMElement::item() in /xxx/xxx.php on line 235.
the code is as follow:
$SMQuery = new DOMDocument();
$SMQuery->loadXML($params);
$response = $SMQuery->createElement('SMreply');
$errors = array();
if (!$reqtyp = $SMQuery->getElementsByTagName("tag1"))
{$errors[] = $SMQuery->createElement('error', 'tag1 Element is missing');}
if (!$reqtyp = $SMQuery->getElementsByTagName("tag2"))
{$errors[] = $SMQuery->createElement('error', 'tag2 Element is missing');}
......
if(!empty($errors))
{
foreach($errors as $error) {
$response->appendChild($error); <==== this line is causing the error !!!
}
}
Any help is much appreciated.
Cheers,
Riki.
You don't show where $response is being defined, but if it's the result of another new DOMDocument(), then that explains you error - you can't add nodes from one DOM object to another directly. It has to be imported first via ->importNode(). Only after that can you actually append it.