You are here: Re: Upload problem « PHP Programming Language « IT news, forums, messages
Re: Upload problem

Posted by Andy Hassall on 10/08/06 22:46

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/comp.lang.php/browse_frm/thread/f08fa4b647284bca/

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация