Jump to content

recording path in the database


franknu

Recommended Posts

  Can anyone tell me why is not working.

the problem is that file is being uploaded on a diffrent folder
and it is not saving the path int the database

i want the file to be upload it in this folder

("/home/townsfin/public_html/business_images/ ")

and instead it is being send to this folder

("/home/townsfin/public_html/")

on top of that it is not saving the  path in the database for the file

here is my code
[code=php:0]
<?php
       
       

$uploaddir = realpath ("/home/townsfin/public_html/business_images/ ");
$uploadfile = $uploaddir . basename($_FILES['Picture1']['name']);

if(!empty($_FILES['Picture1']))
{
    var_dump($uploaddir);
   
    var_dump($_FILES['Picture1']['size']);
    var_dump($_FILES['Picture1']['error']);
    var_dump($_FILE);
    var_dump($_FILES['Picture1']['type']);
    var_dump($_FILES['Picture1']['name']);
   
      }

  if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $uploaddir .$_FILES['Picture1']['name']))
   
    {
      echo("File Uploaded");
      echo("$uploaddir");
      echo("$uploadfile");
  }
   
  else
   
  {
      echo ("file no uploaded!");
      print_r($_FILES);
      echo realpath('./');
  }


 

?>
[/code]












Link to comment
https://forums.phpfreaks.com/topic/31114-recording-path-in-the-database/
Share on other sites

Why are you using realpath() on a path that's already 'real'?

The following should work fine:

[code]<?php
$uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here
$uploadfile = $_FILES['Picture1']['name']; // No need for basename() here

if(!empty($_FILES['Picture1'])){
  var_dump($uploaddir);
   
  var_dump($_FILES['Picture1']['size']);
  var_dump($_FILES['Picture1']['error']);
  var_dump($_FILE);
  var_dump($_FILES['Picture1']['type']);
  var_dump($_FILES['Picture1']['name']);
}

$fullpath = $uploaddir . $uploadfile;
if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){
  echo("File Uploaded");
  echo("$uploaddir");
  echo("$uploadfile");
}
else {
  echo ("file no uploaded!");
  print_r($_FILES);
  echo realpath('./');
}
?>[/code]

Regards
Huggie
ok this is where i want to post the file path in my database
[code=php:0]
$uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here
$uploadfile = $_FILES['Picture1']['name']; // No need for basename() here

if(!empty($_FILES['Picture1'])){
  var_dump($uploaddir);
   
  var_dump($_FILES['Picture1']['size']);
  var_dump($_FILES['Picture1']['error']);
  var_dump($_FILE);
  var_dump($_FILES['Picture1']['type']);
  var_dump($_FILES['Picture1']['name']);
}

$fullpath = $uploaddir . $uploadfile;

if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){
  echo("File Uploaded");
// FILE PATH INSERT  COLUM Picture1
  $sql="INSERT INTO `business_info` where (`Picture1`=`Picture1`)
}
else {
  echo ("file no uploaded!");
  print_r($_FILES);
  echo realpath('./');
}




[/code]

any idea what i should do there

my error message

Parse error: syntax error, unexpected T_STRING in /home/townsfin/public_html/html_forms/insert_data.php on line 142
OK, something like this would do it...

[code]<?php
$uploaddir = '/home/townsfin/public_html/business_images/'; // No need for realpath() here
$uploadfile = $_FILES['Picture1']['name']; // No need for basename() here

if(!empty($_FILES['Picture1'])){
  var_dump($uploaddir);
   
  var_dump($_FILES['Picture1']['size']);
  var_dump($_FILES['Picture1']['error']);
  var_dump($_FILE);
  var_dump($_FILES['Picture1']['type']);
  var_dump($_FILES['Picture1']['name']);
}

$fullpath = $uploaddir . $uploadfile;
if (move_uploaded_file($_FILES['Picture1']['tmp_name'], $fullpath)){
  echo("File Uploaded");
  $sql = "INSERT INTO business_info (picture1) VALUES ('$fullpath')";
  $result = mysql_query($sql);
  if (!$result){
      echo "Error inserting data: " . mysql_error();
  }
}
else {
  echo ("file no uploaded!");
  print_r($_FILES);
  echo realpath('./');
}
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.