php文件上传路径怎么找,如何获取PHP中上传文件的完整路径?

到目前为止,我的代码段:

if(isset($_POST['submit'])) {

$uploaddir = '/www/csvExtraction/uploads/';

$uploadfile = $uploaddir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {

}

还是我得到这个错误

Undefined index: file in C:\wamp\www\csvExtraction\index.php

完整代码:

if(!$db)

die("no db");

if(!mysqli_select_db($db,"phptester"))

die("No database selected.");

if(isset($_POST['submit']))

{

$uploaddir = '/www/csvExtraction/uploads/';

$uploadfile = $uploaddir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))

{

$handle = fopen("$uploadfile", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)

{

$import="INSERT into sample(id,name,address) values('$data[0]','$data[1]','$data[2]')";

mysqli_query($import) or die(mysql_error());

}

fclose($handle);

print "Import done";

}

}

else

{

print "

";

print "Choose file to import:
";

print "
";

//print "
";

print "

";

}

?>

解决方法:

我有解决办法.

$db = mysqli_connect("localhost", "root", "") or die("could not connect");

if(!$db)

die("no db");

if(!mysqli_select_db($db,"phptester"))

die("No database selected.");

if(isset($_POST['submit']))

{

$uploaddir = 'uploads/';

$uploadfile = $uploaddir . basename($_FILES["file"]["name"]);

echo $uploadfile;

if (move_uploaded_file($_FILES["file"]["tmp_name"], $uploadfile))

{

$handle = fopen("$uploadfile", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)

{

$import="INSERT into sample(id,name,address) values('$data[0]','$data[1]','$data[2]')";

mysqli_query($db,$import) or die(mysql_error());

}

fclose($handle);

print "Import done";

}

}

else

{

print "

";

print "Choose file to import:
";

print "
";

print "

";

}

?>

标签:html,php

来源: https://codeday.me/bug/20191028/1954014.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值