我试图通过在本地服务器上创建zip文件来下载2个文件.该文件以zip格式下载但是当我尝试提取它时.它给出错误: 找不到中心目录签名.此文件不是zip文件,也不构成多部分存档的一个磁盘.在后一种情况下,中心目录和zip文件注释将在此存档的最后一个磁盘上找到.
我正在使用以下代码:
<?php
$file_names = array('iMUST Operating Manual V1.3a.pdf','iMUST Product Information Sheet.pdf');
//Archive name
$archive_file_name=$name.'iMUST_Products.zip';
//Download Files path
$file_path=$_SERVER['DOCUMENT_ROOT'].'/Harshal/files/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
//echo $file_path;die;
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
//echo $file_path.$files,$files."
}
$zip->close();
//then send the headers to force download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name"); …Run Code Online (Sandbox Code Playgroud) 我知道这里已经有人问过这个问题:How to set initial state for useState Hook in jest andase?
const [state, setState] = useState([]);
Run Code Online (Sandbox Code Playgroud)
我完全同意Jimmy's Answer从测试文件中模拟 useState 函数,但我有这个问题的一些扩展版本,“如果我有多个 useState 语句进入钩子,我如何测试它们并为它们分配相应的自定义值?”
我有一些带有钩子状态值条件的 JSX 渲染,并且取决于JSX正在渲染的该状态的值。
如何通过将这些 JSX 放入wrapper我的测试用例代码中来测试它们?
我想使用STRIPE PHP API为客户创建付款,为此我找到了创建客户的代码,但没有为他们创建付款.
创建客户的代码:https: //stripe.com/docs/api#create_customer
require_once('./lib/Stripe.php');
Stripe::setApiKey("sk_test_k9NE13Q2LjsIvYTNQHiP5C5H");
Stripe_Customer::create(
array( "description" => "Customer for test@example.com",
"card" => "tok_1509ycG2gfbJDdl3oYWMe6yq" // obtained with Stripe.js
));
Run Code Online (Sandbox Code Playgroud)
我的情景是:我有一些产品和客户来到我的网站并购买产品,但有些客户将来自联盟会员横幅,我们需要向联盟会员客户支付一些佣金.
因此,对于这种情况,我必须创建客户并为他们创建付款,我找到了用于创建客户的PHP API代码,但没有为客户创建付款.
我想在重定向链接上显示内容更新的成功消息.这是我的控制器代码: -
public function add_content()
{
$this->load->helper('url');
$id=$this->input->post('id');
$content=$this->input->post('content');
$title=$this->input->post('title');
$this->load->model('admin/contentmodel');
$status=$this->contentmodel->addcontent($id,$title,$content);
if($status==1)
{
$this->session->set_flashdata("message","<font class='success'>Content Successfully Updated..!!</font>");
redirect('admin/login/dash');
}
else
{
$this->session->set_flashdata("message","<font class='success'>Content Not Updated..!!</font>");
redirect('admin/content/home');
}
}
Run Code Online (Sandbox Code Playgroud)
我的内容已成功更新,现在我想在特定的重定向链接上向用户显示该消息.因为我在上面的代码中设置了消息:
$this->session->set_flashdata("message","<font class='success'>Content Successfully Updated..!!</font>");
Run Code Online (Sandbox Code Playgroud)
所以,你们可以让我知道我哪里出错了,我怎么能在视图上显示错误信息?当我的重定向转到控制器 - >而不是在view.so我如何从控制器 - >视图流出我的错误MSG .提前致谢.
我想更改php文件的扩展名.例如,在浏览器中调用home.php文件,它应该像home.html一样显示.我可以在codeigniter中通过在配置文件中使用后缀变量来完成它.但我怎样才能在核心php中实现它?我认为可以通过.htaccess文件完成,也可以通过其他方式完成,但怎么办?请告诉我.
我尝试:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.html
Run Code Online (Sandbox Code Playgroud)
通过使用上面的代码我尝试但它没有改变?或者如果有其他办法,请告诉我.
我已经在我的Yii模型类中编写了电子邮件规则:
array('first_name, last_name, email, password, cpassword, user_type', 'required'),
array('email', 'email','message'=>"The email isn't correct"),
array('email', 'unique','message'=>"Email already exists!"),
Run Code Online (Sandbox Code Playgroud)
它适用于所有方案,如注册,登录和更新密码,但在忘记密码的功能,unique验证也有效.我想在忘记密码功能时跳过此验证规则,我只想查看电子邮件和所需功能的语法.
那么我们如何才能跳过unique针对不同(忘记密码)功能的特定验证呢?
我有一个多选框:
<select name="tar[]" multiple="multiple" style="height:100px;" id="select1">
<?php foreach($lists as $list){ ?>
<option value="<?php echo $list['des_id']; ?>"><?php echo $list['designation']; ?></option>
<?php } ?>
</select>
Run Code Online (Sandbox Code Playgroud)
在控制器我试图获取所选字段的值,但未能得到它,我得到像2或3的值.
$target = $this->input->post('tar');
print_r($target);die;
Run Code Online (Sandbox Code Playgroud)
我做得对吗?请指导我.谢谢.
我试图使用PostgreSQL的ANY函数从数组interger类型列中搜索值.
我的SQL:
SELECT
*
FROM
company_employee_contacts
WHERE
corporate_complaint_type_ids = ANY(ARRAY[1,3]::integer[])
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
错误:运算符不存在:整数[] =整数
任何人都可以告诉我为什么我在进行类型转换时会收到此错误?
我有一个从数据库中检索值的代码。但我想以相反的顺序获取这些值。见这个例子
While($row=mysql_fetch_assoc($rs)){
echo $row['id']."<br>";//gives 1 and 2 and so on
echo $row['val']."<br>";// gives abc and def and so on
}
Run Code Online (Sandbox Code Playgroud)
但我想要
2
def
1
abc
Run Code Online (Sandbox Code Playgroud)
我怎么能做到这一点。我不想像使用 ORDER BY 那样使用查询。所以我可以在 PHP End 上控制它吗??
所以根据我的需要,我必须将数据从table1复制到table2,为此我使用INSERT SELECT QUERY.这里是 :
$sql = "INSERT INTO `attribute_details_versions`(`attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`) SELECT `attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`FROM `attribute_details`";
Run Code Online (Sandbox Code Playgroud)
在上面的查询中,数据来自attribute_details复制到attribute_details_versions表,并且工作正常.
但是version表格中还有1列,attribute_details_versions我需要在此列中提交自定义值,如任何整数值(1或2等).这个version column is not exist inattribute_details`表如何使用SELECT INSERT QUERY插入这个自定义值?
任何帮助,将不胜感激.
我正在codeigniter上做一些练习来从数据库中检索数据,我很成功.但是当我想获取特定字段的数据时会出现问题.检索我在本地主机上使用以下URL的特定值:
localhost/codeigniter/index.php/news/view/city-news
Run Code Online (Sandbox Code Playgroud)
新闻是控制器,视图是控制器的方法,城市新闻是参数.
这是我的控制器代码:
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);//here i am getting the slug value.
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
Run Code Online (Sandbox Code Playgroud)
这个方法调用模型news_model的方法get_news($ slug).这个方法的代码是:
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}
echo $slug;//here is i m also getting the slug value.
$query = $this->db->get_where('news', array('slug' => $slug));//i think this is not working properly
print_r($query->row_array());die;//now i am getting values here.
return …Run Code Online (Sandbox Code Playgroud) 我有一个视图$all_set上的数组,其中包含一些ids.now我想在控制器中使用表单submit.for传递此数组,我使用j子编码和解码.
在我看来:
<?php $all_set=json_encode($all_set); ?>
<input type="hidden" name="all_set" value="<?php echo serialize($all_set); ?>">
Run Code Online (Sandbox Code Playgroud)
上面的值包含(正如我在页面源中看到的):
<input type="hidden" name="all_set" value="s:26:"{"0":"1","5":"2","13":"3"}";">
Run Code Online (Sandbox Code Playgroud)
现在在控制器上:
$result=$this->input->post('all_set');
$result= unserialize($result);
$result=json_decode($result);
print_r($result); die;
Run Code Online (Sandbox Code Playgroud)
这给了我错误,我没有在控制器上获得任何数组.错误:
Message: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes
Run Code Online (Sandbox Code Playgroud)
为什么会这样?请帮忙.
我想从URL中删除哈希以及后面的任何内容.例如,我可能有:
http://example.com/#question_1
Run Code Online (Sandbox Code Playgroud)
...滑到问题没有.1显示错误消息.当用户的输入然后通过验证时,我需要#question_1从当前位置删除.
我已经尝试了所有这些,但它们都没有为我工作:
document.location.href.replace(location.hash, "");window.location.hash.split('#')[0];window.location.hash.substr(0, window.location.hash.indexOf('#'));注意:我不只是想获取URL - 我想从地址栏中删除它.
php ×10
codeigniter ×4
javascript ×2
select ×2
sql ×2
.htaccess ×1
any ×1
api ×1
core ×1
database ×1
download ×1
email ×1
enzyme ×1
fetch ×1
insert ×1
jquery ×1
json ×1
message ×1
mysql ×1
postgresql ×1
react-hooks ×1
reactjs ×1
url ×1
validation ×1
where ×1
while-loop ×1
yii ×1
zip ×1