Jump to content

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.