dongzhong7299 2009-10-21 06:44
浏览 42

在PHP中上传文件时出错

While uploading the file in php i am not able to upload all types of file, if any space is there in between file name that is not able to download. Please can anyone correct this code

here is my upload code

<?php

$target_path = "../mt/sites/default/files/ourfiles/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}



$con = mysql_connect("localhost","mt","mt");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }else{
 echo "Connected";
}

// Create table
mysql_select_db("mt", $con);

mysql_query("INSERT INTO mt_upload (FileName, FilePath)
VALUES ('".basename( $_FILES['uploadedfile']['name'])."', '".$target_path.basename( $_FILES['uploadedfile']['name'])."')");


// Execute query
mysql_query($sql,$con);

mysql_close($con);



?>
  • 写回答

2条回答 默认 最新

  • doucha5080 2009-10-21 06:53
    关注

    Not sure if this works, but try to change line 2 to this:

    $target_path = $target_path . basename( urldecode ( $_FILES['uploadedfile']['name'] ) ); 
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度