开发者

copy() function error

开发者 https://www.devze.com 2023-04-03 02:37 出处:网络
Here is my input field.. <input type=\"file\" name=\"upload_file[]\" value=\"\" id=\" \"/> $attach = $_FILES[\"upload_file[]\"][\"name\"];

Here is my input field..

<input type="file" name="upload_file[]" value="" id=" "/>

$attach = $_FILES["upload_file[]"]["name"];
$sql = "insert into uploadfile(CAT_ID, SUB_CAT_ID, TAG, DESCRIPTION, UF_NAME, UF_NAME1 , GENRE) values('".$category."','".$subcategory."','".$tag."','".$optionaldescription."','".$attach."','".$attach."','".$genre."')";
copy($_FILES['upload_file[]']['tmp_name'], "upload/".$_FILES['upload_file']['name']);
mysql_query($sql);

Warning: copy开发者_StackOverflow社区() [function.copy]: Filename cannot be empty in C:\xampp\htdocs\test\index.php on line 48


There is a dedicated function for that. Please throw out your copy code and use move_uploaded_file.

The error is caused by your attempt to access $_FILES['uploaded_file[]'], which isn't going to exist. PHP will interpret post/get variables ending with [] as arrays; the file you're interested in is probably sitting at $_FILES['uploaded_file'][0].

Please learn to debug your simple PHP applications. Try var_dump($_FILES) to start, it will tell you exactly what is in the $_FILES array.


PHP automatically converts HTML form elements that end in [] to arrays, therefore, access the 0nt element of the array:

$attach = $_FILES["upload_file"][0]["name"];
$sql = "insert into uploadfile(CAT_ID, SUB_CAT_ID, TAG, DESCRIPTION, UF_NAME, UF_NAME1 , GENRE) values('".$category."','".$subcategory."','".$tag."','".$optionaldescription."','".$attach."','".$attach."','".$genre."')";
copy($_FILES['upload_file'][0]['tmp_name'], "upload/".$_FILES['upload_file'][0]['name']);
mysql_query($sql);

In addition, you should be using move_uploaded_file() in place of copy().


use

$_FILES['upload_file'][0]['tmp_name']

yours one does not work because [] is an array

0

精彩评论

暂无评论...
验证码 换一张
取 消