Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

uploading file size zero

Status
Not open for further replies.

nanban

Programmer
Jun 11, 2003
1
0
0
IN
Hai friends,
Iam using windows XP in PHP when i upload file
its working but when i check size it is zero actually the size of the file is about 20kb so file is not uploading correctly is there any thing to do with PHP.ini file
if u have code for upload in windows i.e php+mysql upload.
please send me or correct this code.

my code is


<HTML>
<HEAD><TITLE>Store binary data into SQL Database</TITLE></HEAD>
<BODY>

<?php

if (isset($submit))
{


$home_path = &quot; $dbserver=&quot;localhost&quot;;
$dbname=&quot;image&quot;;
$dbuser=&quot;root&quot;;
$dbpwd=&quot;&quot;;
@mysql_connect(&quot;$dbserver&quot;,&quot;$dbuser&quot;,&quot;&quot;);
@mysql_select_db($dbname);

$data = addslashes(fread(fopen($form_data, &quot;r&quot;), filesize($form_data)));
//echo $dbuser;
$result=&quot;INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) VALUES ('$form_description','$datanow','$form_data_name','$form_data_size','$form_data_type')&quot;;
$query=@mysql_query($result);
//echo $result.&quot;<br>&quot;;
//echo $query;

$id= mysql_insert_id();
print &quot;<p>This file has the following Database ID: <b>$id</b>&quot;;

MYSQL_CLOSE();

}
else
{

?>
<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF; ?>&quot; enctype=&quot;multipart/form-data&quot;>
File Description:<br>
<input type=&quot;text&quot; name=&quot;form_description&quot; size=&quot;40&quot;>
<INPUT TYPE=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;1000000&quot;>
<br>File to upload/store in database:<br>
<input type=&quot;file&quot; name=&quot;form_data&quot; size=&quot;40&quot;>
<p><input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;>
</form>

<?php

}

?>

</BODY>
</HTML>



thanks and regards,
Nanban
 
I recommend you take a look at the PHP online manual section on handling file uploads ( PHP provides greater functionality for handling uploads than you are using.

I also recommend not storing the content of a file in MySQL, but instead storing the name of the file in MySQL and the content of the file on the filesystem.

I even more strongly recommend this when we're talking about web-based apps. In order to send the file from MySQL to the client, you will have to provide the code to fetch the file's contents, set the appropriate content-type, and stream out the file. Why do all that when the web server can do all that for you already?

Want the best answers? Ask the best questions: TANSTAAFL!
 
Ok, before I start there are things you do need to change within your PHP.ini file.

Firstly, do a search for UPLOAD and it will take you straight to the upload section of you .ini file (hopefully). Do the usual, make sure uploads are on, and increase the maximum file size.

Secondly, try increasing the Memory_limit settings (if you want things over 8MB). I've read different sources that say this can also be a maximum limit on your file uploads. Try this if the first part doesn't work.

Thirdly, I never actually got file uploads to work myself with PHP. I tried it more in the sense of upload and write to loacl directory. My problem was more it wouldn't increase the maximum upload past 10MB. I would recomend having a look at Perl to do this. Had more success with Perl because it was able to process the uploaded file in chunks, rather than as one big thing. Chances are you probably can do this in PHP, and hopefully someone will tell you how (and I'll find out as well with their reply).

If everyone does go &quot;NO NO NO, IT SHOULD WORK&quot; maybe it is an XP thing as well, cause I was running an Apache server on XP, so maybe it's something else that hasn't been explored yet with compatability because few of us actually use XP with PHP and then go and complain to the programmers.

Oh, one last thing, just ensure that it is not reading the data into an array (or reading in just one line of the data) and you are only processing one line. In fact, looking over your code, this could be the case. Try getting it to read line by line, and store the lines in an array and then printing them out. (Usual open file stream, while !eof keep reading, etc) When you are sure that it is correctly reading in all the lines, then try with the insertion into the SQL database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top