Php 为什么取消链接在这个脚本上不起作用?
你在下面看到的是我剧本的一部分 问题是,我只需要重新调整大小的拇指图像,而不是原始文件。如果未上载图像,图像将不会重新调整大小,因此过程应如下所示:Php 为什么取消链接在这个脚本上不起作用?,php,image,resize,unlink,Php,Image,Resize,Unlink,你在下面看到的是我剧本的一部分 问题是,我只需要重新调整大小的拇指图像,而不是原始文件。如果未上载图像,图像将不会重新调整大小,因此过程应如下所示: ->创建一个文件夹 ->上载原始图像 ->调整拇指大小并存储拇指 ->删除原始文件 现在,最后一部分(删除)不起作用。我得到这个错误: PHP警告:取消链接($target_file)[function.unlink]:在第X行的/path/file.PHP中没有这样的文件或目录 它没有找到它 if (isset($_REQUEST['Subm
- ->创建一个文件夹
- ->上载原始图像
- ->调整拇指大小并存储拇指
- ->删除原始文件李>
if (isset($_REQUEST['Submit'])) {
mkdir($dirloc, 0755, true);
$i1=$_FILES['image']['name'];
$nw1="$dirloc/".$i1;
if ($i1) {
$copy1 = copy($_FILES['image']['tmp_name'], $nw1);
}
$fileName = $_FILES["image"]["name"];
$kaboom = explode(".", $fileName);
$fileExt = end($kaboom);
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png") {
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
}
$target_file = "$dirloc/$fileName";
$resized_file = "$dirloc/thumb.$fileExt";
$wmax = 150;
$hmax = 150;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
$xxx = $resized_file;
$delete_target_file = unlink('$target_file');
$sql = "INSERT INTO $db_table(path,code,timecode,catg,description,title) values
('$xxx','".mysql_real_escape_string(stripslashes($_REQUEST['code']))."',
'".mysql_real_escape_string(stripslashes($times))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['catg']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['area2']))."',
'".mysql_real_escape_string(stripslashes($_REQUEST['fbox']))."')";
if($result = mysql_query($sql ,$db)) {
$codes = $_REQUEST['code'];
$linkto = "?v=$codes";
echo "<script>window.location = '$linkto'</script>";
} else {
echo "ERROR: ".mysql_error();
}
} else {
// Here comes the form
}
if(isset($\u请求['Submit'])){
mkdir($dirloc,0755,真);
$i1=$_文件['image']['name'];
$nw1=“$dirloc/”$i1;
如果(i1美元){
$copy1=复制($_文件['image']['tmp_名称'],$nw1);
}
$fileName=$_文件[“图像”][“名称”];
$kaboom=explode(“.”,$fileName);
$fileExt=end($kaboom);
函数ak_img_resize($target、$newcopy、$w、$h、$ext){
列表($w_orig,$h_orig)=getimagesize($target);
$scale_ratio=$w_orig/$h_orig;
如果(($w/$h)>$scale\U比率){
$w=$h*$scale\U比率;
}否则{
$h=$w/$scale_比率;
}
$img=“”;
$ext=strtolower($ext);
如果($ext==“gif”){
$img=imagecreatefromformgif($target);
}else if($ext==“png”){
$img=imagecreatefrompng($target);
}否则{
$img=imagecreatefromjpeg($target);
}
$tci=ImageCreateTureColor($w,$h);
imagecopyresampled($tci、$img、0、0、0、$w、$h、$w_-orig、$h_-orig);
图像JPEG($tci,$newcopy,80);
}
$target_file=“$dirloc/$fileName”;
$resized_file=“$dirloc/thumb.$fileExt”;
$wmax=150;
$hmax=150;
ak_img_resize($target_file,$resized_file,$wmax,$hmax,$fileExt);
$xxx=$resized\u文件;
$delete_target_file=取消链接(“$target_file”);
$sql=“插入到$db_表(路径、代码、时间代码、catg、说明、标题)值中
(“$xxx',”.mysql\u real\u escape\u string(stripslashes($\u REQUEST['code']))。”,
“.mysql\u real\u escape\u字符串(stripslashes($times))”,
“.mysql\u real\u escape\u字符串(stripslashes($\u REQUEST['catg']))。”,
“.mysql\u real\u escape\u字符串(带斜杠($\u请求['area2']))。”,
“.mysql\u real\u escape\u字符串(stripslashes($\请求['fbox']))。”)”;
if($result=mysql\u查询($sql,$db)){
$codes=$_请求['code'];
$linkto=“?v=$codes”;
echo“window.location='$linkto';
}否则{
echo“ERROR:.mysql_ERROR();
}
}否则{
//表格来了
}
有人能解释一下为什么不删除它吗?使用双引号或根本不使用任何引号
unlink("$target_file");
或
不解析用单引号括起来的变量。您需要用双引号括起来,或者根本不使用引号。请确保,$target\u file保留文件的绝对路径。“取消链接”似乎找不到要删除的文件。我认为“没有这样的文件或目录”本身就说明了问题。@zol:有时我们需要有新的眼光来发现这些类型的小错误。这是所有开发人员每天都会发生的事情
unlink($target_file);