PHP

  • 单文件上传

    1 前端<form action="表单提交地址" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" value="上传" /></form>2 后端if(isset($_FILES['upload'])) { if($_FILES['upload']['error'] !== UPLOAD_ERR_OK){ exit('上传失败!'); } $save = './uploads/' . time(

  • 使用opendir()函数和readdir()函数读取目录中的内容

    $resource = opendir('./');$file = '';while ($file = readdir($resource)) { echo $file . '<br>';}closedir($resource);

  • 使用scandir()函数查看当前目录下的所有内容

    $dir_info = scandir('./');foreach ($dir_info as $file) { echo $file . '<br>';}

  • 使用GD来制作缩略图

    <?php // 1)加载原图$src_image = imagecreatefromjpeg('images/003.jpg');// 2)按比例计算出缩略图的大小$src_w = imagesx($src_image); //获取原始宽$src_h = imagesy($src_image); //高//缩放比例$scale = 0.25;//按照比例计算出小图的大小$dst_w = $src_w * $scale;$dst_h = $src_h * $scale;// 3)制作空白画布$dst_image = imagecreatetruecolor($dst_w, $dst_h)

  • 使用GD来制作图片水印

    <?php // 1)加载目标图 001.jpg$dst_image = imagecreatefromjpeg('images/001.jpg');// 2)加载水印来源图 005.jpg$src_image = imagecreatefromjpeg('images/005.jpg');//截取相关: 宽62 高105 x224 y152 (左上角是定位点)$src_x = 224;$src_y = 152;$src_w = 62;$src_h = 105;//缩略图 出现在 右下角的位置$dst_w = 62; //缩略图出现在目标图上的宽$dst_h = 105; //高//获取

  • 使用GD来制作文字水印

    <?php // 1)加载图片为画布:$image = imagecreatefromjpeg('images/003.jpg');// 2)在图片上写字://读取图片的宽和高$width = imagesx($image); //宽度$height = imagesy($image); //高度//文字的宽高$size = 25;$angle = 0;$color = imagecolorallocate($image, 255, 255, 255);$fontfile = __DIR__ . '/SFMono-Regular.otf';$text = 'ABC123';//新的: 获