upload file to database has 0 kb

Post any questions you may have here

upload file to database has 0 kb

Postby nmay on Tue May 13, 2008 11:47 pm

I have the following:
Code: Select all
<?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.
nmay
Fresh Boarder
Fresh Boarder
 
Posts: 7
Joined: Wed May 07, 2008 1:35 am

Re:upload file to database has 0 kb

Postby GreyHead on Wed May 14, 2008 10:25 am

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
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
Platinum Boarder
 
Posts: 2965
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:upload file to database has 0 kb

Postby admin on Wed May 14, 2008 5:14 pm

Hi nmay,

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

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
User avatar
admin
Platinum Boarder
Platinum Boarder
 
Posts: 1659
Joined: Mon Aug 14, 2006 5:29 am

Re:upload file to database has 0 kb

Postby nmay on Wed May 14, 2008 5:53 pm

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?
nmay
Fresh Boarder
Fresh Boarder
 
Posts: 7
Joined: Wed May 07, 2008 1:35 am

Re:upload file to database has 0 kb

Postby GreyHead on Thu May 15, 2008 8:11 am

Hi Namy,

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

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
Platinum Boarder
 
Posts: 2965
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:upload file to database has 0 kb

Postby admin on Thu May 15, 2008 7:36 pm

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 ?
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
User avatar
admin
Platinum Boarder
Platinum Boarder
 
Posts: 1659
Joined: Mon Aug 14, 2006 5:29 am

Re:upload file to database has 0 kb

Postby nmay on Fri May 16, 2008 5:42 am

Thank you very much sir, I figured out what the problem is:
Code: Select all
$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?
nmay
Fresh Boarder
Fresh Boarder
 
Posts: 7
Joined: Wed May 07, 2008 1:35 am

Re:upload file to database has 0 kb

Postby GreyHead on Fri May 16, 2008 9:42 am

Hi nmay,

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


See the PHP manual for more info.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
Platinum Boarder
 
Posts: 2965
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany


Return to Questions & Answers

Who is online

Users browsing this forum: Google [Bot], jnendel and 3 guests