Hello

I have a code to select a file from a hard drive and then upload the data into mysql in csv format......
Only problem is it doesn't work - I keep getting the error message
Warning: move_uploaded_file(/home/ppp/ttt/htdocs/fff/test/upload/Machine_test.csv): failed to open stream: Permission denied in /home/ppp/ttt/htdocs/fff/test/upload/machine_upload.php on line 36

Warning: move_uploaded_file(): Unable to move '/tmp/phpso0c7W' to '/home/ppp/ttt/htdocs/fff/test/upload/Machine_test.csv' in /home/ppp/ttt/htdocs/fff/test/upload/machine_upload.php on line 36

Not Possible To Upload Data! Please Try Again

I have checked the file using print_r($_FILES); and I think it is picking up the right file as I get
Array
(
[MachineCsvFile] => Array
(
[name] => Machine_test.csv
[type] => application/octet-stream
[tmp_name] => /tmp/phpso0c7W
[error] => 0
[size] => 5441
)

)

Can anyone see where I am going wrong - thanks

session_start ();					
$_SESSION['username'] = $username;
require_once ('../mysql_connect.php');		//connect to the database
include ('../header.htm');						//show corporate header

$uploadDir = '/home/ppp/ttt/htdocs/fff/test/upload/';
$uploadFile = $uploadDir . $_FILES['MachineCsvFile']['name'];
print "<pre>";

print_r($_FILES);

$filename = $uploadFile; 
$fp = fopen($filename,'rb') or die('could not open file!'); 

while (!feof($fp)){ 

$data = fgetcsv($fp,100000000); 

$MId = addslashes($data[0]); 
$SRef = addslashes($data[1]); 
$CRef = addslashes($data[2]); 
$CoRef = addslashes($data[3]); 
$Name = addslashes($data[4]); 
$SNo = addslashes($data[5]);
$Type = addslashes($data[6]);
$List = addslashes($data[7]);

$sql = "REPLACE INTO tblMachine (MId, SRef, CRef, CoRef, Name, SNo, Type, List) 
VALUES ('$MId', '$SRef', '$CRef', '$CoRef', '$Name', '$SNo', '$Type', '$List')";
$result = mysql_query($sql) 
 or die(mysql_error());

   }

if (move_uploaded_file($_FILES['MachineCsvFile']['tmp_name'], $uploadFile))
{ echo '<div align="center">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><b><font color="#FF0000" face="Arial, Helvetica, sans-serif" size="4">Thank You, <br> The new data has been added to the database</font></b></p>
</div>';   
} else { print "Not Possible To Upload Data! Please Try Again"; } print "</pre>";

    hi,
    make sure the webserver is allowed to write to :
    /home/ppp/ttt/htdocs/fff/test/upload

    regards,
    Nikolas

      thanks Nikolas
      I have changed the settings on the folder to allow 'write' and this now works

        Write a Reply...