Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,上传到输入文本区域后如何获得重命名的文件名?_Php_Forms_File Upload_Image Uploading - Fatal编程技术网

在PHP中,上传到输入文本区域后如何获得重命名的文件名?

在PHP中,上传到输入文本区域后如何获得重命名的文件名?,php,forms,file-upload,image-uploading,Php,Forms,File Upload,Image Uploading,这是我的PHP函数,用于将图像文件上载到目录中 在这个函数中,上传后所有图像文件都会自动重命名,所以,上传后我会得到重命名后的文件名,并将其插入输入文本区域 functions.php function createDir($path){ if (!file_exists($path)) { $old_mask = umask(0); mkdir($path, 0777, TRUE); umask($old_mask); } } function c

这是我的PHP函数,用于将图像文件上载到目录中 在这个函数中,上传后所有图像文件都会自动重命名,所以,上传后我会得到重命名后的文件名,并将其插入输入文本区域

functions.php

    function createDir($path){      
if (!file_exists($path)) {
    $old_mask = umask(0);
    mkdir($path, 0777, TRUE);
    umask($old_mask);
}
}

function createThumb($path1, $path2, $file_type, $new_w, $new_h, $squareSize = ''){
/* read the source image */
$source_image = FALSE;

if (preg_match("/jpg|JPG|jpeg|JPEG/", $file_type)) {
    $source_image = imagecreatefromjpeg($path1);
}
elseif (preg_match("/png|PNG/", $file_type)) {

    if (!$source_image = @imagecreatefrompng($path1)) {
        $source_image = imagecreatefromjpeg($path1);
    }
}
elseif (preg_match("/gif|GIF/", $file_type)) {
    $source_image = imagecreatefromgif($path1);
}       
if ($source_image == FALSE) {
    $source_image = imagecreatefromjpeg($path1);
}

$orig_w = imageSX($source_image);
$orig_h = imageSY($source_image);

if ($orig_w < $new_w && $orig_h < $new_h) {
    $desired_width = $orig_w;
    $desired_height = $orig_h;
} else {
    $scale = min($new_w / $orig_w, $new_h / $orig_h);
    $desired_width = ceil($scale * $orig_w);
    $desired_height = ceil($scale * $orig_h);
}

if ($squareSize != '') {
    $desired_width = $desired_height = $squareSize;
}

/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
// for PNG background white----------->
$kek = imagecolorallocate($virtual_image, 255, 255, 255);
imagefill($virtual_image, 0, 0, $kek);

if ($squareSize == '') {
    /* copy source image at a resized size */
    imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $orig_w, $orig_h);
} else {
    $wm = $orig_w / $squareSize;
    $hm = $orig_h / $squareSize;
    $h_height = $squareSize / 2;
    $w_height = $squareSize / 2;

    if ($orig_w > $orig_h) {
        $adjusted_width = $orig_w / $hm;
        $half_width = $adjusted_width / 2;
        $int_width = $half_width - $w_height;
        imagecopyresampled($virtual_image, $source_image, -$int_width, 0, 0, 0, $adjusted_width, $squareSize, $orig_w, $orig_h);
    }

    elseif (($orig_w <= $orig_h)) {
        $adjusted_height = $orig_h / $wm;
        $half_height = $adjusted_height / 2;
        imagecopyresampled($virtual_image, $source_image, 0,0, 0, 0, $squareSize, $adjusted_height, $orig_w, $orig_h);
    } else {
        imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $squareSize, $squareSize, $orig_w, $orig_h);
    }
}

if (@imagejpeg($virtual_image, $path2, 90)) {
    imagedestroy($virtual_image);
    imagedestroy($source_image);
    return TRUE;
} else {
    return FALSE;
}
}
函数createDir($path){
如果(!file_存在($path)){
$old_mask=umask(0);
mkdir($path,0777,TRUE);
乌玛斯克(旧面具);
}
}
函数createThumb($path1、$path2、$file_-type、$new_-w、$new_-h、$squareSize=''){
/*读取源图像*/
$source_image=FALSE;
if(preg|u匹配(“/jpg | jpg | jpeg | jpeg/”,$file_type)){
$source_image=imagecreatefromjpeg($path1);
}
elseif(preg_match(“/png | png/”,$file_type)){
if(!$source\u image=@imagecreatefrompng($path1)){
$source_image=imagecreatefromjpeg($path1);
}
}
elseif(preg_match(“/gif | gif/”,$file_type)){
$source_image=imagecreatefromformgif($path1);
}       
如果($source_image==FALSE){
$source_image=imagecreatefromjpeg($path1);
}
$orig_w=imageSX($source_image);
$orig_h=imageSY($source_图像);
如果($orig_w<$new_w&&$orig_h<$new_h){
$desired_width=$orig_w;
$desired_height=$orig_h;
}否则{
$scale=min($new_w/$orig_w、$new_h/$orig_h);
$desired_width=ceil($scale*$orig_w);
$desired_height=天花板($scale*$orig_h);
}
如果($squareSize!=''){
$desired_width=$desired_height=$squareSize;
}
/*创建一个新的“虚拟”映像*/
$virtual\u image=ImageCreateTureColor($required\u width,$required\u height);
//对于PNG背景白色----------------->
$kek=imagecolorallocate($virtual_image,255255255);
imagefill($virtual_image,0,0,$kek);
如果($squareSize==''){
/*以调整过的大小复制源图像*/
imagecopyresampled($virtual_image,$source_image,0,0,0,$desired_width,$desired_height,$orig_w,$orig_h);
}否则{
$wm=$orig_w/$squareSize;
$hm=$orig_h/$squareSize;
$h_高度=$squareSize/2;
$w_高度=$squareSize/2;
如果($orig\u w>$orig\u h){
$adjusted_width=$orig_w/$hm;
$half_width=$adjusted_width/2;
$int_width=$half_width-$w_height;
imagecopyresampled($virtual_image,$source_image,$int_width,0,0,$adjusted_width,$squareSize,$orig_w,$orig_h);
}
其他($原价)
<form enctype="multipart/form-data" action="image_upload_demo_submit.php" method="post" name="image_upload_form" id="image_upload_form">
<div id="imgArea"><img src="./img/default.jpg">
  <div class="progressBar">
    <div class="bar"></div>
    <div class="percent">0%</div>
  </div>
  <div id="imgChange"><span>Change Photo</span>
    <input accept="image/*" name="image_upload_file" id="image_upload_file" type="file">
  </div>
</div>
<form method="post" name="gregorian" onclick="calcPersian();" action="../medical/patient_new.php">
<input rows="3" cols="30" id="avatar" name="avatar" value="" type="text">
</form>