For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2006 > Upload problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Upload problem
Shelly

2006-10-08, 6:58 pm

I do what most programmers do -- we steal code from stuff we have written
before, or accept code from others that works, before we attempt to write
something altogether new.

On a previous project I wrote code to upload pictures and music from the
local drive to the server. It worked perfectly. I scarfed that code,
without changing any names, for a new project and I am running into a
problem. Here is what I have:

The form definition:
<form action="" method="post" enctype="multipart/form-data" name="History"
target="_self">
<input type="hidden" name="MAX_FILE_SIZE" value="1250000">

The file field:
<input name="srcFile" type="file" id="srcFile">

The code for the copying:
if (strlen(trim($_FILES['srcFile']['name'])
) > 0) {
$tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
$_FILES['srcFile']['name'];
echo "target=" . $tmp_photo . "<br>";
echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
$status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
echo "status=" . $status . "<br>";
---- more processing follows ----

The result is:
target=pic_sheldonlg_coda_coda.jpg
src=
status=

In other words, it is not finding a value for
$_FILES['srcFile']['tmp_name'], but it is finding the value for
$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
of directories down on the C drive).

This worked fine before. Does anything leap out at anyone?

While I am here, how do you folks handle the time delay in processing the
upload to avoid having impatient users? So far, all I am doing is putting a
message before the hit the key to do the upload.

Shelly




Andy Hassall

2006-10-08, 6:58 pm

On Sun, 08 Oct 2006 22:19:34 GMT, "Shelly" <sheldonlg.news@asap-consult.com>
wrote:

>I do what most programmers do -- we steal code from stuff we have written
>before, or accept code from others that works, before we attempt to write
>something altogether new.
>
>On a previous project I wrote code to upload pictures and music from the
>local drive to the server. It worked perfectly. I scarfed that code,
>without changing any names, for a new project and I am running into a
>problem. Here is what I have:
>
>The form definition:
><form action="" method="post" enctype="multipart/form-data" name="History"
>target="_self">
> <input type="hidden" name="MAX_FILE_SIZE" value="1250000">
>
>The file field:
><input name="srcFile" type="file" id="srcFile">
>
>The code for the copying:
> if (strlen(trim($_FILES['srcFile']['name'])
) > 0) {
> $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
> $_FILES['srcFile']['name'];
> echo "target=" . $tmp_photo . "<br>";
> echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
> $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);


Are you sure you don't want to actually use move_uploaded_file()?

Also using $_POST['petname'] directly in the target filename without
sanitising it (for at the very least things like "/" and "..") is potentially
dangerous.

> echo "status=" . $status . "<br>";
> ---- more processing follows ----
>
>The result is:
>target=pic_sheldonlg_coda_coda.jpg
>src=
>status=
>
>In other words, it is not finding a value for
>$_FILES['srcFile']['tmp_name'], but it is finding the value for
>$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
>of directories down on the C drive).
>
>This worked fine before. Does anything leap out at anyone?


Ask PHP for errors first:

http://uk2.php.net/manual/en/features.file-upload.php

$_FILES fills in an 'error' subscript for each file. Do you also have
error_reporting cranked up to the maximum level?

>While I am here, how do you folks handle the time delay in processing the
>upload to avoid having impatient users? So far, all I am doing is putting a
>message before the hit the key to do the upload.


Short answer, not much you can do. There were some longer answers in a recent
file upload thread on this group:
http://groups.google.co.uk/group/co...8fa4b647284bca/

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Gleep

2006-10-08, 6:58 pm

On Sun, 08 Oct 2006 22:19:34 GMT, "Shelly" <sheldonlg.news@asap-consult.com> wrote:

>I do what most programmers do -- we steal code from stuff we have written
>before, or accept code from others that works, before we attempt to write
>something altogether new.
>
>On a previous project I wrote code to upload pictures and music from the
>local drive to the server. It worked perfectly. I scarfed that code,
>without changing any names, for a new project and I am running into a
>problem. Here is what I have:
>
>The form definition:
><form action="" method="post" enctype="multipart/form-data" name="History"
>target="_self">
> <input type="hidden" name="MAX_FILE_SIZE" value="1250000">
>
>The file field:
><input name="srcFile" type="file" id="srcFile">
>
>The code for the copying:
> if (strlen(trim($_FILES['srcFile']['name'])
) > 0) {
> $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
> $_FILES['srcFile']['name'];
> echo "target=" . $tmp_photo . "<br>";
> echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
> $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
> echo "status=" . $status . "<br>";
> ---- more processing follows ----
>
>The result is:
>target=pic_sheldonlg_coda_coda.jpg
>src=
>status=
>
>In other words, it is not finding a value for
>$_FILES['srcFile']['tmp_name'], but it is finding the value for
>$_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
>of directories down on the C drive).
>
>This worked fine before. Does anything leap out at anyone?
>
>While I am here, how do you folks handle the time delay in processing the
>upload to avoid having impatient users? So far, all I am doing is putting a
>message before the hit the key to do the upload.
>
>Shelly
>



It's hard to say what the problem is because all your code is not posted. First thing I noticed is
that <form action="" .... was empty, but maybe you where just trying to hide that.

If you are not getting the $_FILES['srcFile']['tmp_name'] that tells me something is going
nuts in the upload temp location. First use phpinfo(); to determin where uploads are being
posted to. If you are on a shared host server, this might be tricky to find. But in any event you
should ask for access to shell account so you can get in there and figure out what is going on.
This is getting into the realm of Unix, and you'll have to figure that out on your own. You need to
verify where uploads are being posted to.

Also take a look at php.ini and make sure that the upload limit (filesize) is set to above what
you expect to upload. The default is usually set for 2 Megs, but if you need more you will need at
increase this value, save the file and reboot server so this will take effect. You should be familar
with shell access, putty, vi/pico editor.

Second part of your question. The delay process during uploads. I've done allot of search and do
mean allot... there are progress bars/meters out there for php uploads. Just google (php progress
bar) and you'll see what i mean. Some are free and some you pay. I've tried above 5 of them and
it's not easy to get them running and configured. Some of the commercial pays one don't even work.
Most use a combinatin of php and perl to monitor the progress of the upload, some new one take
advantage of perl. In all these cases you have to configure the temp uploads path and the default
load paths and believe it can be tricky. Then you have to install the perl files in the cgi-bin and
configure the paths in those as well. I have not found one that has a simple install procedure and
shows exactly what I want, so as an alternative i use a little javascript trick and just tell the
user to wait for the upload..

here are my notes that i copied from someone else,

Use a javascript event function with your froms submit button.

Put this in your page head:

<script language="JavaScript">
<!--
function showProgress() {
document.getElementById("progress").style.visibility = 'visible';
document.getElementById("submit").disabled = true;
}
//-->
</script>

Make your submit button call the show progress event function with an onclick:

<input type="submit" name="submit" value="Upload Picture" onclick="java script:showProgress();">

Then stick this next to your submit button:

<span id="progress" style="visibility:hidden"><img
src="http://battlescrypt.scrypted.com/images/busy_blue.gif"/>

That shouldw work out fine for you! Feel free to use that image from my server.




petersprc@gmail.com

2006-10-08, 6:58 pm

Maybe $_FILES['srcFile']['error'] has an error code? I would also make
sure you have write permissions to PHP's upload_tmp_dir
(ini_get('upload_tmp_dir') or phpinfo() will tell you where it is).

As for long uploads, you could warn the user that the upload may take a
while, or unhide a "Please Wait" image.

There are a couple techniques for a real upload progress indicator,
some of which are shown here:

http://devzone.zend.com/node/view/id/36

http://blog.bitflux.ch/archive/2006...or-php-5-2.html

Shelly wrote:
> I do what most programmers do -- we steal code from stuff we have written src
> before, or accept code from others that works, before we attempt to write
> something altogether new.
>
> On a previous project I wrote code to upload pictures and music from the
> local drive to the server. It worked perfectly. I scarfed that code,
> without changing any names, for a new project and I am running into a
> problem. Here is what I have:
>
> The form definition:
> <form action="" method="post" enctype="multipart/form-data" name="History"
> target="_self">
> <input type="hidden" name="MAX_FILE_SIZE" value="1250000">
>
> The file field:
> <input name="srcFile" type="file" id="srcFile">
>
> The code for the copying:
> if (strlen(trim($_FILES['srcFile']['name'])
) > 0) {
> $tmp_photo = "pic_" . $user . "_" . $_POST['petname'] . "_" .
> $_FILES['srcFile']['name'];
> echo "target=" . $tmp_photo . "<br>";
> echo "src=" . $_FILES['srcFile']['tmp_name'] . "<br>";
> $status = copy ($_FILES['srcFile']['tmp_name'], $tmp_photo);
> echo "status=" . $status . "<br>";
> ---- more processing follows ----
>
> The result is:
> target=pic_sheldonlg_coda_coda.jpg
> src=
> status=
>
> In other words, it is not finding a value for
> $_FILES['srcFile']['tmp_name'], but it is finding the value for
> $_FILES['srcFile']['name'] (that value is coda.jpg and is nested a number
> of directories down on the C drive).
>
> This worked fine before. Does anything leap out at anyone?
>
> While I am here, how do you folks handle the time delay in processing the
> upload to avoid having impatient users? So far, all I am doing is putting a
> message before the hit the key to do the upload.
>
> Shelly


Shelly

2006-10-08, 9:57 pm


<petersprc@gmail.com> wrote in message
news:1160349587.512660.324520@e3g2000cwe.googlegroups.com...
> Maybe $_FILES['srcFile']['error'] has an error code? I would also make
> sure you have write permissions to PHP's upload_tmp_dir
> (ini_get('upload_tmp_dir') or phpinfo() will tell you where it is).


I did this and error came up as "2".

The upload_tmp_dir came up as blank when I did it with theo ini_get. Also,
it was "no value" with the phpinfo. Also, phpinfo gave "On" for
file_uploads. What else should I be looking for?

Shelly


>
> As for long uploads, you could warn the user that the upload may take a
> while, or unhide a "Please Wait" image.
>
> There are a couple techniques for a real upload progress indicator,
> some of which are shown here:
>
> http://devzone.zend.com/node/view/id/36
>
> http://blog.bitflux.ch/archive/2006...or-php-5-2.html
>
> Shelly wrote:
>



Shelly

2006-10-08, 9:57 pm


"Gleep" <Gleep@Gleep.com> wrote in message
news:esvii253u6j48jg9kb37iig2bskn4ktaik@
4ax.com...
> On Sun, 08 Oct 2006 22:19:34 GMT, "Shelly"
> <sheldonlg.news@asap-consult.com> wrote:
>
>
>
> It's hard to say what the problem is because all your code is not posted.
> First thing I noticed is
> that <form action="" .... was empty, but maybe you where just
> trying to hide that.


The one that worked before had action=""

>
> If you are not getting the $_FILES['srcFile']['tmp_name'] that
> tells me something is going
> nuts in the upload temp location. First use phpinfo(); to determin
> where uploads are being


It is coming out as blank. phpinfo says "no value".

> posted to. If you are on a shared host server, this might be tricky to
> find. But in any event you
> should ask for access to shell account so you can get in there and figure
> out what is going on.
> This is getting into the realm of Unix, and you'll have to figure that out
> on your own. You need to
> verify where uploads are being posted to.
>
> Also take a look at php.ini and make sure that the upload limit
> (filesize) is set to above what
> you expect to upload. The default is usually set for 2 Megs, but if you
> need more you will need at


My max on the server is 7M. My max filesize specified is 1.25M. this file
is under 1M.

Shelly

> increase this value, save the file and reboot server so this will take
> effect. You should be familar
> with shell access, putty, vi/pico editor.
>
> Second part of your question. The delay process during uploads. I've
> done allot of search and do
> mean allot... there are progress bars/meters out there for php uploads.
> Just google (php progress
> bar) and you'll see what i mean. Some are free and some you pay. I've
> tried above 5 of them and
> it's not easy to get them running and configured. Some of the commercial
> pays one don't even work.
> Most use a combinatin of php and perl to monitor the progress of the
> upload, some new one take
> advantage of perl. In all these cases you have to configure the temp
> uploads path and the default
> load paths and believe it can be tricky. Then you have to install the perl
> files in the cgi-bin and
> configure the paths in those as well. I have not found one that has a
> simple install procedure and
> shows exactly what I want, so as an alternative i use a little javascript
> trick and just tell the
> user to wait for the upload..
>
> here are my notes that i copied from someone else,
>
> Use a javascript event function with your froms submit button.
>
> Put this in your page head:
>
> <script language="JavaScript">
> <!--
> function showProgress() {
> document.getElementById("progress").style.visibility = 'visible';
> document.getElementById("submit").disabled = true;
> }
> //-->
> </script>
>
> Make your submit button call the show progress event function with an
> onclick:
>
> <input type="submit" name="submit" value="Upload Picture"
> onclick="java script:showProgress();">
>
> Then stick this next to your submit button:
>
> <span id="progress" style="visibility:hidden"><img
> src="http://battlescrypt.scrypted.com/images/busy_blue.gif"/>
>
> That shouldw work out fine for you! Feel free to use that image from my
> server.
>
>
>
>



Shelly

2006-10-08, 9:57 pm

I would like to thank you all for the help. It turned out that error=2 was
the giveaway. I needed to increase the mas file size.

Shelly


.:[ ikciu ]:.

2006-10-12, 6:59 pm

Hmm Shelly <sheldonlg.news@asap-consult.com> wrote:
> <form action="" method="post" enctype="multipart/form-data"
> name="History" target="_self">


It looks like xhtml - if yes dont use enctype for from

> if (strlen(trim($_FILES['srcFile']['name'])
) > 0) {



you should to check $_FILES['srcFile']['error']

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this => mysql_query();


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com