好吧,我一直想知道我是否能unlink()正确处理这个功能.我不希望unlink()函数抛出一些讨厌的错误,如果它无法取消链接文件(可能是由于找不到文件).
我试过类似的东西
try {
unlink("secret/secret.txt");
} catch(Exception $e) {
print "whoops!";
//or even leaving it empty so nothing is displayed
}
Run Code Online (Sandbox Code Playgroud)
但它没有用.我不是PHP专家.我搜索并在网络的某个地方找到了这个异常处理代码.但是,正如我记得上学时间,Java也是如此.它应该有效.我不知道代码有什么问题.
或者我可以简单地使用if..else语句
if(unlink($file)){
//leaving here empty must ensure that nothing is displayed
}else{
//leaving here empty must ensure that nothing is displayed
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码也没有用.我在哪里做错了?有什么其他方法可以正确处理它?
可以通过错误报告(PHP)(生产和开发环境)进行操作来隐藏错误吗?
通过codeigniter文档,我使用以下代码强制从我的服务器下载文件.
function download($file_id){
$file = $this->uploadmodel->getById($file_id); //getting all the file details
//for $file_id (all details are stored in DB)
$data = file_get_contents($file->full_path); // Read the file's contents
$name = $file->file_name;;
force_download($name, $data);
}
Run Code Online (Sandbox Code Playgroud)
代码是图像的工作文件,但是当它附带PDF文件的情况时,它不起作用.我没有测试它的所有文件扩展名,但由于它不适用于PDF,它可能不适用于其他各种文件类型.有解决方案吗
我想在浏览器中完全加载或下载图像后加载图像。我不想在下载图像时显示图像。相反,我想显示该图像的较低质量版本,直到在背景中加载高质量图像,并且当图像在背景中完全加载时,我想用该图像替换较低质量的图像。
我有两张图片,说
$LQimage = "LQabc.jpg";
$HQimg = "HQabc.jpg";
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它工作?
编辑 通过@codebox 发布的答案,此代码有效..谢谢:)
<html>
<head>
<script type="text/javascript">
function load(){
var img = new Image();
var imgUrl = 'HQabc.jpg';
img.onload = function(){
// this gets run once the image has finished downloading
document.getElementById('pp').src = imgUrl;
}
img.src = imgUrl; // this causes the image to get downloaded in the background
}
</script>
</head>
<body onload="load()">
<img id="pp" src="LQabc.jpg" width=600/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我不知道这是否是一个逻辑问题,但是,我有一个奇怪的问题或提出了一个奇怪的要求。我需要访问动态生成的变量的值。
data:{
brand: undefined,
model: undefined
}
methods:{
check(){
let fields = ['brand', 'model'];
for(let i in fields){
console.log(`this.${fields[i]}`) // I need this to access the field values
}
}
}
Run Code Online (Sandbox Code Playgroud) 我想生成唯一的数字,以便我可以使用它们作为参考号来处理我的客户端请求.
我不希望重复这些数字也不是我使用任何数据库来存储数字.
我只是想用一个简单的算法来生成随机数.
我正在使用类似的东西
rand(10*45, 100*98)
有可能做那样的事情.我知道我的要求似乎很奇怪,但我只是想知道它是否可能.
<?php
class Page extends CI_Controller{
function index(){
$this->view('home');
}
public function view($page = 'home')
{
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
Run Code Online (Sandbox Code Playgroud)
我想查看的链接页面作为http://www.mydomain.com/page/about,http://www.mydomain.com/page/services 等不格式http://www.mydomain.com/ page/view/about和http://www.mydomain.com/page/view/services
我怎么能这样做?
我基本上想做的是将一个图像调整为两个不同大小的图像。但是我只能先调整大小,featured_$filename而不能调整大小thumb_$filename。
最初,我尝试创建单个函数,并将配置作为数组传递,但没有成功,但同一件事,仅调整了单个图像的大小。
$this->resizeImage($imagePath, $file['upload_data']['file_name']);
$this->resizeThumb($imagePath, $file['upload_data']['filename']);
public function resizeImage($imagePath, $filename){
$config['image_library'] = 'gd2';
$config['source_image'] = $imagePath;
$config['create_thumb'] = FALSE;
$config['new_image'] = 'featured_'.$filename;
$config['maintain_ratio'] = TRUE;
$config['width'] = 570;
$config['height'] = 372;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
}
public function resizeThumb($imagePath, $filename){
$config['image_library'] = 'gd2';
$config['source_image'] = $imagePath;
$config['create_thumb'] = FALSE;
$config['new_image'] = 'thumb_'.$filename;
$config['maintain_ratio'] = TRUE;
$config['width'] = 180;
$config['height'] = 135;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();
}
Run Code Online (Sandbox Code Playgroud) 我想要一个下拉列表,说出以下选项.如果没有选择任何选项,我想要一个请选择信息.我已通过以下代码实现了它.选择一个选项时,将提交表单.但问题是当我导航回页面并选择第一个选项,即 - 请选择 - 时,我的表单也会提交给该选项.是否有任何解决方案,以便我可以在没有选择选项时显示--please select--选项而不提交该特定表格 - 请选择 - 选项.
<select onchange="this.form.submit()">
<option>--Please Select --</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Run Code Online (Sandbox Code Playgroud) 我有一个链接,当点击显示<div>包含一个<form>.我想在再次单击链接时隐藏<div>包含<form>,并在单击时再次显示它.我创建了一个简单的Jquery来隐藏div.如何在单击相同链接时实现它以显示/隐藏.
$("#customize").click(function(){
$("#cust").hide('slow');
return false;
});
Run Code Online (Sandbox Code Playgroud) 我在$ categories变量中返回了result_array(),现在我想创建一个下拉菜单.但是如果我直接使用变量,那么将显示数组的所有元素.但是我只想显示名称并将其id保持为值.我该怎么做?
$options = $categories;
echo form_dropdown('category', $options);
Run Code Online (Sandbox Code Playgroud)
我想要类似的东西
<select name="category">
<option value="1"> ABC </option>
.....
<option value="10"> NNNC </option>
</select>
Run Code Online (Sandbox Code Playgroud) 我使用下面的函数将我的图像文件上传到我的服务器(Localhost).很好,图像正在上传.但是我需要两个图像字段,因此一旦点击提交按钮,就应该上传两个图像.我使用了这里描述的Codeigniter多文件上传功能,但它无法正常工作.
我收到此错误消息
A PHP Error was encountered
Severity: Warning
Message: is_uploaded_file() expects parameter 1 to be string, array given
Filename: libraries/Upload.php
Line Number: 161
Run Code Online (Sandbox Code Playgroud)
好吧,我无法理解错误在哪里.我用来上传单张图片的功能是
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpeg|png|gif';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
//failed display the errors
}
else
{
//success
}
}
Run Code Online (Sandbox Code Playgroud)
另外我还想问我可以更改我选择的输入字段名称.即我总是需要实施<input type="file" name="userfile"/>.是否可以更改名称?我尝试更改它,我收到消息没有选择文件,所以这必须意味着我无法改变它.
我有一个变量对象存储下面的值.
Array
(
[0] => stdClass Object
(
[term_id] => 1
[name] => Uncategorized
[slug] => uncategorized
[term_group] => 0
[term_taxonomy_id] => 1
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 4
[object_id] => 39
[cat_ID] => 1
[category_count] => 4
[category_description] =>
[cat_name] => Uncategorized
[category_nicename] => uncategorized
[category_parent] => 0
)
)
Run Code Online (Sandbox Code Playgroud)
我现在想要显示slug值列表.我怎么做的?
php ×10
codeigniter ×5
html ×5
jquery ×2
arrays ×1
file-upload ×1
javascript ×1
object ×1
random ×1
unlink ×1
vue.js ×1