我需要允许我的网站上的用户在上传后将其图像从服务器上删除,如果他们不再需要它们的话.我以前unlink
在PHP中使用该函数,但后来被告知这可能存在风险并且存在安全问题.(上面的代码:)
if(unlink($path.'image1.jpg')){
// deleted
}
Run Code Online (Sandbox Code Playgroud)
相反,我现在只想将文件移动到另一个文件夹中.这必须能够在他们首次上传文件后很长时间内完成,以便他们在登录帐户时.如果我有存储用户图像的主文件夹:
user/
Run Code Online (Sandbox Code Playgroud)
然后在一个名为del的文件夹中,这是放置其不需要的图像的目的地:
user/del/
Run Code Online (Sandbox Code Playgroud)
是否有将文件移动到其他文件夹的命令?所以说:
user/image1.jpg
Run Code Online (Sandbox Code Playgroud)
移动到/变成
user/del/image1.jpg
Run Code Online (Sandbox Code Playgroud) 我有一个下拉框如下:
<select id="select_Boiler">
<option value="boiler_1645">Vaillant 831</option>
<option value="boiler_2373">Worcester 24</option>
<option value="boiler_3009">Vaillant 835</option>
<option value="boiler_4354">Bosch 671</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我需要能够使用jQuery删除特定选项,但基于文本而不是选项值.我试过这个没有成功:
jQuery("#select_Boiler option[text='Vaillant 835']").remove();
Run Code Online (Sandbox Code Playgroud)
我知道我可以用以下的价值做同样的事情并且它有效,但我需要通过文字来做
jQuery("#select_Boiler option[value='boiler_3009']").remove();
Run Code Online (Sandbox Code Playgroud) 我有一批像这样的字符串:
tHe iPad hAS gONE ouT of STOCK
PoWER uP YOur iPhone
wHAT moDEL is YOUR aPPLE iPHOne
Run Code Online (Sandbox Code Playgroud)
我想将每个单词的第一个字符大写,并将其余字符小写 - 除了iPhone
or的任何引用iPad
。如:
通过使用:
ucwords(strtolower($string));
Run Code Online (Sandbox Code Playgroud)
这可以完成大部分需要的工作,但显然也可以在iPad
和 上完成iPhone
:
The Ipad Has Gone Out Of Stock
Power Up Your Iphone
What Model Is Your Apple Iphone
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现以下目标:
The iPad Has Gone Out Of Stock
Power Up Your iPhone
What Model Is Your Apple iPhone
Run Code Online (Sandbox Code Playgroud) 我需要在我的magento商店中创建4个新的客户属性.我已经创建了一个模块,如下所示:
Customerattribute >
etc > config.xml
Model > Mysql4 > Setup.php
sql > customerattribute_setup > mysql4-install-0.0.1.php
Run Code Online (Sandbox Code Playgroud)
config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Custom_Customerattribute>
<version>0.0.1</version>
</Custom_Customerattribute>
</modules>
<global>
<resources>
<customerattribute_setup>
<setup>
<module>Custom_Customerattribute</module>
<class>Custom_Customerattribute_Model_Mysql4_Setup</class>
</setup>
....
</customerattribute_setup>
</resources>
</global>
</config>
Run Code Online (Sandbox Code Playgroud)
Setup.php
class Custom_Customerattribute_Model_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
/**
* This method returns true if the attribute exists.
*
* @param string|int $entityTypeId
* @param string|int $attributeId
* @return bool
*/
public function attributeExists($entityTypeId, $attributeId)
{
try
{
$entityTypeId = $this->getEntityTypeId($entityTypeId);
$attributeId = $this->getAttributeId($entityTypeId, …
Run Code Online (Sandbox Code Playgroud) 我使用 PHP 和 GD 来裁剪并输出图像,代码如下。它工作正常,但是当我将透明 PNG 传递给它时,我会生成黑色背景。我怎样才能阻止这个?
//setup
switch ($source_type) {
case IMAGETYPE_JPEG: $source = imagecreatefromjpeg($img_path); break;
case IMAGETYPE_PNG: $source = imagecreatefrompng($img_path); break;
}
// setup cropped destination
$cropped = imagecreatetruecolor($cropped_width, $cropped_height);
// create cropped image
$x = (($source_width / 100) * IMAGE_X) - ($cropped_width / 2);
$y = (($source_height / 100) * IMAGE_Y) - ($cropped_height / 2);
imagecopy(
$cropped,
$source,
0, 0,
$x, $y,
$cropped_width, $cropped_height
);
// output inc header
header('Content-type: image/jpeg');
imagejpeg($cropped);
Run Code Online (Sandbox Code Playgroud) 我将以下代码用于带有Siema的滑块:
https://codepen.io/pawelgrzybek/pen/boQQWy
它使用扩展类向幻灯片添加点。一切正常,除了我们的网站现在在使用 ES6 进行 Google 移动友好测试时遇到问题,因为它给出了错误:
Uncaught SyntaxError: Unexpected reserved word
Run Code Online (Sandbox Code Playgroud)
在这一行:
class SiemaWithDots extends Siema {
Run Code Online (Sandbox Code Playgroud)
有没有办法让它与 ES5 兼容?
代码如下:
// instantiate new extended Siema
const mySiemaWithDots = new SiemaWithDots({
// on init trigger method created above
onInit: function(){
this.addDots();
this.updateDots();
},
// on change trigger method created above
onChange: function(){
this.updateDots()
},
});
// extend a Siema class by two methods
// addDots - to create a markup for dots
// updateDots - to update …
Run Code Online (Sandbox Code Playgroud) 我有这样一个数组:
$animals = array (
'giraffe',
'lion',
'hippo',
'dog',
'cat',
'rabbit',
'fly',
'hamster',
'gerbil'
'goldfish'
);
Run Code Online (Sandbox Code Playgroud)
那就是我希望数组与这些2分开的顺序- hamster
和gerbil
我想随机选择哪个先出现。我知道我可以使用:
shuffle($animals);
Run Code Online (Sandbox Code Playgroud)
要将它们全部随机化,但是我只想为这2个做。所以,如果我要这样做,print_r($animals)
我可能会在仓鼠之前先让仓鼠来,而在仓鼠之前又要让沙鼠来。
我刚开始使用 PHP 的 Imageick 库。
我首先裁剪用户图像,如下所示:
$img_path = 'image.jpg';
$img = new Imagick($img_path);
$img_d = $img->getImageGeometry();
$img_w = $img_d['width'];
$img_h = $img_d['height'];
$crop_w = 225;
$crop_h = 430;
$crop_x = ($img_w - $crop_w) / 2;
$crop_y = ($img_h - $crop_h) / 2;
$img->cropImage($img_w, $img_h, $crop_x, $crop_y);
Run Code Online (Sandbox Code Playgroud)
我现在需要将 225 x 430 的裁剪图像放置在中心 500 像素 x 500 像素的新图像上。新图像必须具有透明背景。像这样(灰色边框只是视觉效果):
我怎么能这样做?我尝试了 2 个选项:
compositeImage()
$trans = '500x500_empty_transparent.png';
$holder = new Imagick($trans);
$holder->compositeImage($img, imagick::COMPOSITE_DEFAULT, 0, 0);
Run Code Online (Sandbox Code Playgroud)
通过在 500x500px 处制作一个没有任何内容的透明 png,我希望我可以compositeImage
用来将图像放在上面。它这样做但不保持原始大小,$holder
而是使用 225x430 …
我刚刚开始研究html5和canvas元素,并试图创建一个简单的页面,按钮点击顺时针和逆时针旋转图像.我设法得到一些工作,但我在ie10上测试它,图像没有显示,只是空白的灰色画布.我只能测试ie10,所以不确定这是否会影响其他版本.我的完整代码是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
<!-- Canvas Element -->
<canvas id="canvas" width="500" height="500" style="background-color: #EAEAEA;">
</canvas>
<!-- Rotate Buttons -->
<h2>Rotate</h2>
<button onclick="rotate('c')">Clockwise</button>
<button onclick="rotate('a')">Anti-Clockwise</button>
<button onclick="rotate('r')">Reset</button>
<script type="text/javascript">
const FPS = 30;
var imagePosX = 90;
var imagePosY = 143;
var imageRot = 0;
var image = new Image();
image.src = "sample.jpg";
var canvas = null;
var context2D = null;
window.onload = startup;
function startup(){
canvas = document.getElementById('canvas');
context2D = canvas.getContext('2d');
setInterval(draw, 500 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个可以计算两个日期之间的天数的函数.我目前有以下,但它给了我一些意想不到的结果:
function dayCount($from, $to) {
$first_date = strtotime($from);
$second_date = strtotime($to);
$offset = $second_date-$first_date;
return floor($offset/60/60/24);
}
print dayCount($s, $e).' Days';
Run Code Online (Sandbox Code Playgroud)
几个正确的例子:
$s = '18-03-2016';
$e = '25-03-2016';
Run Code Online (Sandbox Code Playgroud)
输出:7 Days
- 正确
$s = '03-02-2016';
$e = '06-02-2016';
Run Code Online (Sandbox Code Playgroud)
输出:3 Days
- 正确
$s = '06-04-2016';
$e = '27-04-2016';
Run Code Online (Sandbox Code Playgroud)
输出:21 Days
- 正确
但是,如果我有两个月之间的交叉日期,有时它是正确的,有时它显示一天更少:
$s = '25-03-2016';
$e = '01-04-2016';
Run Code Online (Sandbox Code Playgroud)
产出:6 Days
- 应为7天
$s = '23-02-2016';
$e = '01-03-2016';
Run Code Online (Sandbox Code Playgroud)
输出:7 Days
- 正确
我试图通过点击按钮在我的kineticjs阶段更改图像的src.
我有一个可拖动的图像(在这种情况下是darth-vader)和顶部的静态图像(在这种情况下是猴子).单击一个按钮,我希望能够用新的替换可拖动的图像(yoda)
JSFiddle可以在这里看到:
我想到了以下几点:
btn.addEventListener("click", function (event) {
mainImage.src = path+'yoda.jpg';
layer.removeChildren();
draw(mainImage,true);
draw(foregroundImage,true);
Run Code Online (Sandbox Code Playgroud)
});
将完成它:首先通过更新src,然后删除所有对象并以正确的顺序重新绘制它们.
出于某种原因,虽然我得到了2张yoda图像放在舞台上 - 1正确落后但另一个高于其他一切......
我在PHP中有一个现有的数组(当我使用时print_r
):
Array (
[0] => Array(
[value] => 188
[label] => Lucy
)
[1] => Array (
[value] => 189
[label] => Jessica
)
[2] => Array (
[value] => 192
[label] => Lisa
)
[3] => Array (
[value] => 167
[label] => Carol
)
// and so on...
)
Run Code Online (Sandbox Code Playgroud)
从这个数组我需要操作或创建一个新的数组,如下所示:
Array (
[Lucy] => 188
[Jessica] => 189
[Lisa] => 192
[Carol] => 167
)
Run Code Online (Sandbox Code Playgroud)
这样做的最佳方法是什么?
我需要名字成为键,所以我可以按字母顺序排序,如下所示:
uksort($array, 'strnatcasecmp');
Run Code Online (Sandbox Code Playgroud) php ×7
arrays ×2
alpha ×1
attributes ×1
canvas ×1
capitalize ×1
class ×1
count ×1
date ×1
directory ×1
ecmascript-5 ×1
ecmascript-6 ×1
extend ×1
gd ×1
html ×1
html5 ×1
image ×1
imagick ×1
javascript ×1
jquery ×1
kineticjs ×1
lowercase ×1
magento ×1
module ×1
move ×1
option ×1
select ×1
shuffle ×1
sorting ×1
src ×1
string ×1
transparency ×1
unlink ×1