Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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 - Fatal编程技术网

PHP代码,删除重命名

PHP代码,删除重命名,php,Php,如果可能的话,我想请你帮个忙,我一直在尝试更改它,但我没有成功,我想在我的php文件中更改它,但没有结果 现在,下面的脚本是一个调整大小的脚本,但它重命名了我的文件。。。我不需要它这样做,你能看看它,告诉我如何删除重命名的文件吗 我知道这与:$image->createFile(md5($tempFile));我试着移除md5,但还是什么都没有 谢谢 function setFile($src = null) { $this->ext = strtoupper(pathinfo($src,

如果可能的话,我想请你帮个忙,我一直在尝试更改它,但我没有成功,我想在我的php文件中更改它,但没有结果

现在,下面的脚本是一个调整大小的脚本,但它重命名了我的文件。。。我不需要它这样做,你能看看它,告诉我如何删除重命名的文件吗

我知道这与:$image->createFile(md5($tempFile));我试着移除md5,但还是什么都没有

谢谢

function setFile($src = null) {
$this->ext = strtoupper(pathinfo($src, PATHINFO_EXTENSION));
if(is_file($src) && ($this->ext == "JPG" OR $this->ext == "JPEG")) {
$this->img_r = ImageCreateFromJPEG($src);
} elseif(is_file($src) && $this->ext == "PNG") {
$this->img_r = ImageCreateFromPNG($src);
} elseif(is_file($src) && $this->ext == "GIF") {
$this->img_r = ImageCreateFromGIF($src);
}
$this->img_w = imagesx($this->img_r);
$this->img_h = imagesy($this->img_r);
}

function resize($largestSide = 100) {
$width = imagesx($this->img_r);
$height = imagesy($this->img_r);
$newWidth = 0;
$newHeight = 0;

if($width > $height){
$newWidth = $largestSide;
$newHeight = $height * ($newWidth / $width);
}else{
$newHeight = $largestSide;
$newWidth = $width * ($newHeight / $height);
}

$this->dst_r = ImageCreateTrueColor($newWidth, $newHeight);
imagecopyresampled($this->dst_r, $this->img_r, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
$this->img_r = $this->dst_r;
$this->img_h = $newHeight;
$this->img_w = $newWidth;
}

function createFile($output_filename = null) {
if($this->ext == "JPG" OR $this->ext == "JPEG") {
imageJPEG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext, $this->quality);
} elseif($this->ext == "PNG") {
imagePNG($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
} elseif($this->ext == "GIF") {
imageGIF($this->dst_r, $this->uploaddir.$output_filename.'.'.$this->ext);
}
$this->output = $this->uploaddir.$output_filename.'.'.$this->ext;
}

function setUploadDir($dirname) {
$this->uploaddir = $dirname;
}

function flush() {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

imagedestroy($this->dst_r);
unlink($targetFile);
imagedestroy($this->img_r);

}

}

$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

move_uploaded_file ($tempFile, $targetFile);

$image = new Image();
$image->setFile($targetFile);
$image->setUploadDir($targetPath);
$image->resize(800);
$image->createFile(md5($tempFile));
试着换成

$image->createFile('resized_'.$_FILES['Filedata']['name']);


function createFile($output_filename = null) {
    if($this->ext == "JPG" OR $this->ext == "JPEG") {
        imageJPEG($this->dst_r, $this->uploaddir.$output_filename, $this->quality);
    } elseif($this->ext == "PNG") {
        imagePNG($this->dst_r, $this->uploaddir.$output_filename);
    } elseif($this->ext == "GIF") {
        imageGIF($this->dst_r, $this->uploaddir.$output_filename);
    }
    $this->output = $this->uploaddir.$output_filename;
}

将文件的实际名称(
$\u FILES['Filedata']['name']
)与临时名称(
$\u FILES['Filedata']['tmp\u name']
)混淆。第一个是客户端上传的文件。第二个是服务器在服务器的机器上创建的临时文件。因此,您必须在此处使用实际的客户端名称。

这将使您的一天更加愉快

$image->createFile(preg_replace("/\.[^\.]*$/", "", $targetFile));

嘿,对不起,你;re right:/我一直在更改javascript文件,无意中我说javascript:/查看$\u文件的含义。您的图像保存为服务器上的临时文件;需要一个新名称来存储它。现在使用$_FILES['Fildedata']['temp_name']执行此操作。提供更多选项。对,然后删除md5()。嘿,谢谢:)成功了,你能帮我再做一件事吗,我需要删除.PNG、.JPG等。。。因为名称类似于:Default.png.png这是因为您的函数
function createFile()
正在添加扩展名,即
md5()
文件名,只需从该函数的每一行中删除
。$this->ext
。嘿,谢谢。。事实上,当我删除该扩展时,它根本不会创建图像…请确保您完全按照我所说的方式删除<代码>“.”。$this->ext