473,473 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP file upload unexpected error - file too large?

Hi,
I have a short basic script to upload files. It works fine with small files,
but with longer files it gets stuck.

Here's the fragment, the input file is loaded in "$file" from an HTML form
as usual.

....
$img_str = fread(fopen($file, "r"), filesize($file));
$data = addslashes($img_str);
// --------------------- up to here the execution is correct and fast (<1
second)

$sql="INSERT INTO $table (".
" file_name,".
" file_type,".
" file_size,".
" bin_data)".
" VALUES (".
" '$file_name',".
" '$file_type',".
" '$file_size',".
" '$data')";
// --------------------- it gets stuck
here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mysql_query($sql) or die ("SQL error ..$sql");

I have already set the php.ini variables as follows:
memory_limit = 16M
upload_max_filesize = 6M

I also checked the execution time to max_execution_time = 300 (even though I
don't believe it should be necessary).
The server is a P4 1.8 GHz, 256MB RAM

Any suggestion? Am I missing out something?

Thanks in advance,
G.


Jul 17 '05 #1
6 2524
Giulio Neri wrote:
Hi,
I have a short basic script to upload files. It works fine with small
files, but with longer files it gets stuck.

Here's the fragment, the input file is loaded in "$file" from an HTML form
as usual.

...
$img_str = fread(fopen($file, "r"), filesize($file));
$data = addslashes($img_str);
// --------------------- up to here the execution is correct and fast (<1
second)

$sql="INSERT INTO $table (".
" file_name,".
" file_type,".
" file_size,".
" bin_data)".
" VALUES (".
" '$file_name',".
" '$file_type',".
" '$file_size',".
" '$data')";
Are you aware that the query is very strange?
Since you put ' instead of " around stringliterals, the SQL you produce
might differ somewhat from what you expect.

Always try:
echo $sql;
before posting to a newsgroup. :P

You will have something like this:

INSERT INTO sometable (file_name,file_type,file_size,bin_data)
VALUES
('$file_name', '$file_type' etc. etc)

instead of the expected VALUES for the vars you use.

Check your ' and "

Regards,
Erwin Moller
// --------------------- it gets stuck
here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mysql_query($sql) or die ("SQL error ..$sql");

I have already set the php.ini variables as follows:
memory_limit = 16M
upload_max_filesize = 6M

I also checked the execution time to max_execution_time = 300 (even though
I don't believe it should be necessary).
The server is a P4 1.8 GHz, 256MB RAM

Any suggestion? Am I missing out something?

Thanks in advance,
G.


Jul 17 '05 #2
Erwin,
the single quotation mark is required in the sql syntax to insert text /
non-numeric values (mysql gives me an error otherwise).

The real problem here is that the string concatenation fails and I cannot
make it work...

I also tried with something like:

$sql="hello: $data";

or

$sql="hello: " . $data;

and in both cases it fails (I believe it runs out of memory...).

The file size is 4MB.
Thanks for any additional advise.
G.
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Giulio Neri wrote:
Hi,
I have a short basic script to upload files. It works fine with small
files, but with longer files it gets stuck.

Here's the fragment, the input file is loaded in "$file" from an HTML form as usual.

...
$img_str = fread(fopen($file, "r"), filesize($file));
$data = addslashes($img_str);
// --------------------- up to here the execution is correct and fast (<1 second)

$sql="INSERT INTO $table (".
" file_name,".
" file_type,".
" file_size,".
" bin_data)".
" VALUES (".
" '$file_name',".
" '$file_type',".
" '$file_size',".
" '$data')";


Are you aware that the query is very strange?
Since you put ' instead of " around stringliterals, the SQL you produce
might differ somewhat from what you expect.

Always try:
echo $sql;
before posting to a newsgroup. :P

You will have something like this:

INSERT INTO sometable (file_name,file_type,file_size,bin_data)
VALUES
('$file_name', '$file_type' etc. etc)

instead of the expected VALUES for the vars you use.

Check your ' and "

Regards,
Erwin Moller
// --------------------- it gets stuck
here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mysql_query($sql) or die ("SQL error ..$sql");

I have already set the php.ini variables as follows:
memory_limit = 16M
upload_max_filesize = 6M

I also checked the execution time to max_execution_time = 300 (even though I don't believe it should be necessary).
The server is a P4 1.8 GHz, 256MB RAM

Any suggestion? Am I missing out something?

Thanks in advance,
G.

Jul 17 '05 #3
Giulio Neri wrote:
Erwin,
the single quotation mark is required in the sql syntax to insert text /
non-numeric values (mysql gives me an error otherwise).

Right,

But did you echo the SQL-string before executing?
What came out?

Regards,
Erwin Moller
The real problem here is that the string concatenation fails and I cannot
make it work...
that is why I advised you to check the ' and " in the first place.

Try something like this.

$sql="INSERT INTO $table (file_name,file_type,file_size,bin_data)";
$sql.= "VALUES ('".$file_name"', '".$file_type."' etc. etc

Just use . to concatenate.

Good luck.
Let me/us know if you succeed.

Regards,
Erwin Moller


I also tried with something like:

$sql="hello: $data";

or

$sql="hello: " . $data;

and in both cases it fails (I believe it runs out of memory...).

The file size is 4MB.
Thanks for any additional advise.
G.
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Giulio Neri wrote:
> Hi,
> I have a short basic script to upload files. It works fine with small
> files, but with longer files it gets stuck.
>
> Here's the fragment, the input file is loaded in "$file" from an HTML form > as usual.
>
> ...
> $img_str = fread(fopen($file, "r"), filesize($file));
> $data = addslashes($img_str);
> // --------------------- up to here the execution is correct and fast (<1 > second)
>
> $sql="INSERT INTO $table (".
> " file_name,".
> " file_type,".
> " file_size,".
> " bin_data)".
> " VALUES (".
> " '$file_name',".
> " '$file_type',".
> " '$file_size',".
> " '$data')";


Are you aware that the query is very strange?
Since you put ' instead of " around stringliterals, the SQL you produce
might differ somewhat from what you expect.

Always try:
echo $sql;
before posting to a newsgroup. :P

You will have something like this:

INSERT INTO sometable (file_name,file_type,file_size,bin_data)
VALUES
('$file_name', '$file_type' etc. etc)

instead of the expected VALUES for the vars you use.

Check your ' and "

Regards,
Erwin Moller
> // --------------------- it gets stuck
> here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> mysql_query($sql) or die ("SQL error ..$sql");
>
> I have already set the php.ini variables as follows:
> memory_limit = 16M
> upload_max_filesize = 6M
>
> I also checked the execution time to max_execution_time = 300 (even though > I don't believe it should be necessary).
> The server is a P4 1.8 GHz, 256MB RAM
>
> Any suggestion? Am I missing out something?
>
> Thanks in advance,
> G.


Jul 17 '05 #4
Hi Erwin,
I did insert a exit($sql); before executing as well as a exit("test");

in both cases the program did not reach the exit command line

It is almost definitely something to do with the string concatenation, as
many other tests I have done show and I don;t know how to get around that!

Thanks for helping me.

"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Giulio Neri wrote:
Erwin,
the single quotation mark is required in the sql syntax to insert text /
non-numeric values (mysql gives me an error otherwise).


Right,

But did you echo the SQL-string before executing?
What came out?

Regards,
Erwin Moller
The real problem here is that the string concatenation fails and I cannot make it work...


that is why I advised you to check the ' and " in the first place.

Try something like this.

$sql="INSERT INTO $table (file_name,file_type,file_size,bin_data)";
$sql.= "VALUES ('".$file_name"', '".$file_type."' etc. etc

Just use . to concatenate.

Good luck.
Let me/us know if you succeed.

Regards,
Erwin Moller


I also tried with something like:

$sql="hello: $data";

or

$sql="hello: " . $data;

and in both cases it fails (I believe it runs out of memory...).

The file size is 4MB.
Thanks for any additional advise.
G.
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Giulio Neri wrote:

> Hi,
> I have a short basic script to upload files. It works fine with small
> files, but with longer files it gets stuck.
>
> Here's the fragment, the input file is loaded in "$file" from an HTML

form
> as usual.
>
> ...
> $img_str = fread(fopen($file, "r"), filesize($file));
> $data = addslashes($img_str);
> // --------------------- up to here the execution is correct and
fast (<1
> second)
>
> $sql="INSERT INTO $table (".
> " file_name,".
> " file_type,".
> " file_size,".
> " bin_data)".
> " VALUES (".
> " '$file_name',".
> " '$file_type',".
> " '$file_size',".
> " '$data')";

Are you aware that the query is very strange?
Since you put ' instead of " around stringliterals, the SQL you produce
might differ somewhat from what you expect.

Always try:
echo $sql;
before posting to a newsgroup. :P

You will have something like this:

INSERT INTO sometable (file_name,file_type,file_size,bin_data)
VALUES
('$file_name', '$file_type' etc. etc)

instead of the expected VALUES for the vars you use.

Check your ' and "

Regards,
Erwin Moller

> // --------------------- it gets stuck
> here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> mysql_query($sql) or die ("SQL error ..$sql");
>
> I have already set the php.ini variables as follows:
> memory_limit = 16M
> upload_max_filesize = 6M
>
> I also checked the execution time to max_execution_time = 300 (even

though
> I don't believe it should be necessary).
> The server is a P4 1.8 GHz, 256MB RAM
>
> Any suggestion? Am I missing out something?
>
> Thanks in advance,
> G.

Jul 17 '05 #5
Giulio Neri wrote:
Hi Erwin,
I did insert a exit($sql); before executing as well as a exit("test");

in both cases the program did not reach the exit command line

It is almost definitely something to do with the string concatenation, as
many other tests I have done show and I don;t know how to get around that!

Thanks for helping me.


Did you read the rest of my posting?
It contained an improved $sql statement.
Try to use it in your situation.

(I said 2 times, 'Regards, Erwin Moller')
So that probably made you stop reading after the first. :P
Sorry.

Regards,
Erwin Moller

Jul 17 '05 #6
The syntax I used is the same reported in many SQL, MySQL and PHP manuals.

Anyway I solved the problem:

1- increased memory available to script
memory_limit = 16M
upload_max_filesize = 6M

2- use of unset($temp_variables) in order to release memory

3- set mysql configuration file option:
max_allowed_packet=16M

It all works now...

Thanks anyway,
G.
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:42***********************@news.xs4all.nl...
Giulio Neri wrote:
Hi Erwin,
I did insert a exit($sql); before executing as well as a exit("test");

in both cases the program did not reach the exit command line

It is almost definitely something to do with the string concatenation, as many other tests I have done show and I don;t know how to get around that!
Thanks for helping me.


Did you read the rest of my posting?
It contained an improved $sql statement.
Try to use it in your situation.

(I said 2 times, 'Regards, Erwin Moller')
So that probably made you stop reading after the first. :P
Sorry.

Regards,
Erwin Moller

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
0
by: pruebauno | last post by:
Hello all, I am having issues compiling Python with large file support. I tried forcing the configure script to add it but then it bombs in the make process. Any help will be appreciated. ...
6
by: Thomas Due | last post by:
Hi, I am writing an ASP.NET project where I allow users to upload files to the server. I have changed to web.config to allow a total file size of 100MB. My problem is that if the total file size...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
6
by: Paul | last post by:
Hi there, When adding a "File Field" HTML control to an aspx page to facilitate file uploading, the following occurs: 1. You select a file that is larger than the allowed size limit. 2. Once...
6
by: tshad | last post by:
I have an upload file input as: <input id="MyFile" style="width:300px" type="File" runat="Server"> This works fine, but I find that if my page doesn't pass validation during postback, the page...
4
by: jf li | last post by:
I have a Asp.net web application and a Asp.net Web service application. The Web application is using HtmlInputFile to get a 50M size of file selected by end user, read the data of this file and...
4
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.