ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

upload file to database has 0 kb

nmay 13 May, 2008
I have the following:
<?php
if(isset($_POST['upload']) && $_FILES['result']['size'] > 0)
{
$fileName1 = $_FILES['result']['name'];
$tmpName1 = $_FILES['result']['tmp_name'];
$fileSize1 = $_FILES['result']['size'];
$fileType1 = $_FILES['result']['type'];
}

$fp = fopen($tmpName1, 'r');
$content = fread($fp, filesize($tmpName1));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{ $fileName1 = addslashes($fileName1);
}     
$user =& JFactory::getUser();
$userid = $user->get('id');

$database =& JFactory::getDBO();

$testquery = "INSERT INTO jos_uploads (userid, name, type, size, content) " .
"VALUES ('$userid', '$fileName1', '$fileType1', '$fileSize1', '$content')";

$database->setQuery($testquery);

if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>
";
}
?>
The problem is the uploaded file 's size is 0 kb. I am using windows xp. What's wrong? I had it worked on another machine.
GreyHead 14 May, 2008
Hi nmay,

Sorry, I've no real idea - this isn't ChronoForms code as far as I can see. Where are you putting it? Is the file uploading OK from the form?

Bob
Max_admin 14 May, 2008
Hi nmay,

you had it working with the same DB structure ? the field type to store the file is of which type ?

Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
nmay 14 May, 2008
The above code was stored in auto generated code box, I had it working one time on a different machine. I am storing JPGs PDFs Zips users uploaded into MYSQL. But when I use MYSQLADMIN to download the file, it is 0 kb. I checked the upload folder, looks like files are there. I also changed var $mosConfig_fileperms = '0644';

And my debugging statement is telling me that $tmpName1 is C:\tempuploads\phpA.tmp (I am using windows) But nothing present in that folder, even I have full permission to that folder, tested , writable. $fp and $content are null, I guess that's why content (blob) is empty.

Could you please help me with it?
GreyHead 15 May, 2008
Hi Namy,

ChronoForms moves the file from that temp folder into components/com_chronocontact/uploads. Do you see anything there?

Bob
Max_admin 15 May, 2008
Hi nmay,

from your words I understand that there is a problem uploading files to the server then, I think you should start by removing this code and trying Chronoforms upload tool, do your files get uploaded ? if not then there is something must be fixed on your machine, whats it exactly... I'm not sure, try contacting your host support, or if you have a local machine then you will need to configure something!

Cheers

Max

P.S: do you have FTP settings configured in your joomla admin ? may be this affecting it someway ? try to use the FTP functions ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
nmay 16 May, 2008
Thank you very much sir, I figured out what the problem is:
$fp = fopen($tmpName1, 'r');


The above code is reading file at apache's upload file directory specified in php.ini (C:\temp, but actual files are stored in
C:\apache\htdocs\components\com_chronocontact\upload

That is why $fp is null. What I am trying to accomplish is to store files users uploaded in mysql, so I need use $fp to read the file. In my mind, there are two options:

1. Modify your code so that uploads are uploaded to c:\temp

2. Move pointer $fp to C:\apache\htdocs\components\com_chronocontact\upload

I am a super php noob. Can you give me little instructions or tell me few lines of codes I need to look at?
GreyHead 16 May, 2008
Hi nmay,

Put the file path into the fopen function:
 fopen('path'.$file_name, 'r')

See the PHP manual for more info.

Bob
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com