Forums

PHP

This topic is locked

PHP Upload Retrieving File Names

Posted 22 Jan 2002 18:17:28
1
has voted
22 Jan 2002 18:17:28 Pat Heuber posted:
i would be interested very much to find a way how to use PHP Upload and insert record at the same time. Even better, if there is a way to retrieve the file name of the chosen file in a form field at the same time, so that the user doesn't have to type at in again.

I know that there was an earlier posting dealing with this subject. But that didn't give me any clues.

Any Tutorial ?

Replies

Replied 06 Feb 2002 13:27:00
06 Feb 2002 13:27:00 A H replied:
Hey,

This is what i did. It's not a very clean way to do it but it works.

Create your form for inserting the record.
Include a file field and name it whatever your database field is called. (mine was photos)

Apply the insert record server behaviour. Choose the file field to insert into the photo field in your database table. Put in a redirect page (check for details below).

Apply the upload behaviour. Choose the file filed in your form again to upload the image from.

I select not to check for file size, or use re-directs, etc.

After applying the behaviour, go to the code view.

Insert this bit of code (change it to your names), just before the // *** Insert Record: part.

<?php
if ($photo_name == "" {
$photo2 = "photos/nophoto.jpg";
} else {
$photo2 = "photos/$photo_name";
}
?>

Then change the field in this line "$MM_fieldsStr" from photo to photo2.

Here's what it does. Uploads the image. If an image was uploaded it adds photos/ before the filename of the image and inserts the text into the photo field in the database.
If there is no image uploaded it puts photos/nophoto.jpg into the database so there is no broken image on the page. Just make either a small gif file or an image that says "no photo available" or something.

Notes. If you need to redirect the page after the insert is done, you will need to comment out a few lines of the upload behaviour code. Otherwise you will get an error about headers already being written.

As i'm not a very good programmer, and wasnt sure what the bear essentials of the upload behaviour were, i just commented out a few lines of Tims code (sorry Tim).

Find these parts and modify as follows:

// tg_OpenWin();


function tg_CloseWin() {
// echo "<script language=\"Javascript\">\n";
// echo "uploadWindow.close();\n";
// echo "</script>\n";


It's a bit dodgy but it works. Until someonme brings out a server behaviour that will have to do <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>


I'll post a full page of code here. [Link Removed by Request]



Edited by - hyperbuzzy on 06 Feb 2002 13:28:21

Edited by - rawveg on 24 Oct 2002 11:49:27
Replied 08 Jul 2002 19:32:49
08 Jul 2002 19:32:49 dyna c replied:
The answer is old - But the correction is needed as other may use this process outlined to you.

see for full instructions
www.udzone.com/showDetail.asp?TypeId=3&NewsId=730

The

<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
i would be interested very much to find a way how to use PHP Upload and insert record at the same time. Even better, if there is a way to retrieve the file name of the chosen file in a form field at the same time, so that the user doesn't have to type at in again.

I know that there was an earlier posting dealing with this subject. But that didn't give me any clues.

Any Tutorial ?


<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Replied 14 Oct 2002 19:04:02
14 Oct 2002 19:04:02 Samir Butt replied:
Hey Hyperbuzzy,

I hope your still around cause I could use some of your assistance.
First of all, for not being a programmer that was a sweet job modifying Tim's script.
Thing is, I tried exactly how you explained, and it works. But if I leave the file field blank the database table is not updated with a record. It works fine if i specify an image but not if I dont.

Any ideas? Thanks.

Edited by - trying2design on 14 Oct 2002 19:04:19

Reply to this topic