Page 1 of 1

saving path in the database

Posted: Mon Dec 18, 2006 10:12 am
by franknu
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 in 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: Select all

<?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('./'); 
   } 


   

?>

Posted: Mon Dec 18, 2006 10:14 am
by RobertGonzalez
What are all those var_dump() calls telling you?

Posted: Mon Dec 18, 2006 10:26 am
by franknu
well info such as size

bool(false) int(29457) int(0) NULL string(9) "image/gif" string(30) "christmas-bells-with-holly.gif" File Uploadedchristmas-bells-with-holly.gif

Posted: Mon Dec 18, 2006 10:39 am
by RobertGonzalez
I suppose more specifically I should ask what var_dump($uploaddir); is telling you.

Posted: Mon Dec 18, 2006 10:41 am
by franknu
ok it is bring the file where i want the only problem now is tha it is not saving the path in the database

Code: Select all

<?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('./'); 
}
?>

Posted: Mon Dec 18, 2006 10:44 am
by volka
franknu wrote:ok it is bring the file where i want the only problem now is tha it is not saving the path in the database
Where's the code for putting the file path into the database?

Posted: Mon Dec 18, 2006 10:52 am
by franknu
ok, i thought that this would automaticly would do so just because i have a colum call Picture1

Posted: Mon Dec 18, 2006 10:58 am
by volka
8O No, a file upload does not do something like that automagically.
What type of database are you using? What do you want to store, where and when?

Posted: Mon Dec 18, 2006 11:08 am
by franknu

Code: Select all

$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` where `Picture1`=`Picture1` // this is where i want the file path to go to
} 
else { 
   echo ("file no uploaded!"); 
   print_r($_FILES); 
   echo realpath('./'); 
}

Posted: Mon Dec 18, 2006 11:15 am
by franknu
this is my error message

Code: Select all

Parse error: syntax error, unexpected T_STRING in /home/townsfin/public_html/html_forms/insert_data.php on line 142
thank you

Posted: Mon Dec 18, 2006 11:29 am
by RobertGonzalez
Show lines 140 to 150 of your code please.

Posted: Mon Dec 18, 2006 11:45 am
by franknu
$sql="INSERT INTO `business_info` where (`Picture1`=`Picture1`)

Posted: Mon Dec 18, 2006 12:02 pm
by volka
$sql="INSERT INTO `business_info` where `Picture1`=`Picture1` // this is where i want the file path to go to
it's missing a " to end the string literal.
An INSERT statement has no WHERE clause.
You have to send the sql statement to the database.
What type of database do you use? (possible answers: mysql, postgresq, sqlite, mssql ....)

Posted: Mon Dec 18, 2006 12:18 pm
by RobertGonzalez
MySQL syntax for INSERT queries.

Code: Select all

INSERT INTO `tableName` (`fieldName1`, `fieldName2`, `fieldName3`) VALUES (intValue, 'strValue', '#dateValue#');