uploading file with php ,getting error with file name
i am trying to transfer file from user to my server and than upload the file , the issue is when i know the file name(hard code) the file is being uploaded perfectly fine .and the file is transferred to my folder but the issue is i cannot get the file name in my fopen function.i have tried storing it in a varaible and try fopen($a.csv,"r") or fopen(($_FILES["file"]["name"].csv", "r")) but get the error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\pm\upload.php on line... HEERE IS MY CODE can some one fix my problem ?
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
$a=$_FILES["file"]["name"];}
}
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("pm", $con);
$du开发者_开发百科m=false;
if (($handle = fopen($_FILES["file"]["name"].csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
. .. ... ....
the error is on the line if (($handle = fopen($_FILES["file"]["name"].csv", "r")) !== FALSE) { have tried to upload without extension of the file ! kindly help
Try:
if (($handle = fopen('upload/'.$_FILES['file']['name'], 'r')) !== FALSE) {
You moved the file to the upload
directory, that's where you should read it from.
精彩评论