English 中文(简体)
图像领域
原标题:Error with Image field
  • 时间:2011-06-29 15:00:14
  •  标签:
  • php

如果名称领域和档案领域相同,该文字就会产生错误。 如果我想上载<代码>a.jpg的文档,而且名称领域也比照其更名的错误<代码>a。 让我知道,消除这一问题,帮助删除以前的文件。

$username=$name ;
move_uploaded_file($_FILES["pic"]["tmp_name"],"albumpic/".$_FILES["pic"]["name"]);
$ext=substr($_FILES["pic"]["name"],strpos($_FILES["pic"]["name"],".")); 
if(file_exists("albumpic/$username$ext"))   { unlink("albumpic/$username$ext"); }

rename( "albumpic/".$_FILES["pic"]["name"],"albumpic/$username$ext");

$newphoto="$username$ext";
//var_dump($photo);
$err="";
最佳回答

这是一种非常恶劣的法典。 您首先将用户提供的文件移至上面任何内容。 你以不可靠的方式提取文件延期(如果有人上载<条码>。 之后,你重新命名了上载的AFTER号档案,该档案可能淹没以前的东西。

考虑一下你将“Joe”和“Fred”用户带上“joe.jpg”和“fred.jpg”的形象。 如果Fred上载了新形象,即“工作”。 你的系统将摧毁Joe的形象。

相反:

$ext = pathinfo($_FILES[ pic ][ name ], PATHINFO_EXTENSION);

if (file_exists("albumpic/$username$ext")) {
    unlink("albumpic/$username$ext");
}

if (!move_uploaded_file($_FILES[ pic ][ tmp_name ], "albumpic/$username$ext")) {
   die("Unable to move user $username s picture to album directory");
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签