Getting and passing the file name during upload

03-26-04, 05:06 PM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Getting and passing the file name during upload
I have been working on a "script" all day and it has been one step forward and two steps back !!!
I am off to bed now as had enough.
Could someone help me with the problem below ready for the morning : )
Anthony
I am up loading some files using :
This works great and my files are up loaded BUT I need to get the filename and send it to Mysql and I have no idea how to do it.
I was getting the file names from the directory afterwards but I have added "unlink($filename);" now and the file disapears before I can get the name. The thumb directory has all the old and new files so they are repeated in the database - see what I mean about one step forward and 2 steps back - I blame NeverMind for this problem LOL
|

03-26-04, 10:44 PM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
I'm not sure if I'm following you quite right, but what about logging your $filename in an array or something before you unlink it (or them)? The logic here is, to unlink a file, you have to know the filename, and if you know the filename before unlinking it, log it for the later use.
Then you can just INSERT them into the database.
Excuse me if I'm off. =)
__________________
Blavv =|
|

03-27-04, 03:13 AM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
What I want
Thanks for looking blaw.
The script I am using allows me to "browse" my hard drive for the files I want to upload. I then click on "Submit" and they are uploaded to my host.
So I need to include in the bit of script someway of passing the name of the files to another page to then upload into Mysql.
So you are right in saying I need to log them in an array but I am not sure how to do it.
Anthony
|

03-27-04, 03:42 AM
|
 |
Junior Code Guru
|
|
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi there,
It's getting a little late where I am so I can't "stay" for a long time, but as I can see, you're letting the user browse the hard drive via input tag of type "file". then multiple files that are selected will be uploaded to the server where your script is running. Now, you need to simultaneously (well, not literally) INSERT the file name of the file you are uploading into MySQL (NOT the file itself, I mean). Is it correct?
I don't see any unlink() in your code, so again, I'm sorry if I'm off, but if you want to do what I just mentioned, simply bug an INSERT statement in a loop like so (One line added, accompanied with a comment):
But if you must pass each file name to a different page for this task (maybe among with other operations), then you can have this instead of the mysql_query() line:
In the end of the loop, you get an array $my_array that contains all the filenames that are uploaded. Then you can pass this array in SESSION, GET, or even POST (with curl), etc, to another page where you do your DB stuff.
I don't know - does it help?
__________________
Blavv =|
|

03-27-04, 04:01 AM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Thanks blaw
Its morning here now not night and the wife wants to go out shopping so I will have to try this out later.
This here is the first part of a script and I will put them all together when I get all the bits to work.
The script will - upload the files to the host ( bit you can see here ) - make a thumbnail, low qulity watermarked version and a normal version ( imagemagick ). The uploaded file will be deleted ( as it can be any size file ) usink Unlink as well as a tempory version of the file ( need to get from uploaded file to low qulity watermarked version ).
These files then will be available for searching and inserting into tables using different settings set by the user in a drop down list.
I think I will use your second method as I need to insert some "text, "date", and who the photo is of into the database as well and I can then do all that straight away on a page when uploading rather than go into the database later and edit.
Thanks Again for the help Anthony
|

03-27-04, 08:25 AM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Bit more help please
Its taking me hours to sort the simplest things !!
I have this bit of code still that adds the pics to the server and I have added a couple of " session " bits. this now puts something like "image.jpg" into the session that I can now get in the second script.
I now have a second bit of script that takes the values from the array in the session and populates the " name " box of the form.
All seems OK down to here and here are my problem's :
1/ When I upload the variables to this table and Mysql I want "image" not "image.jpg". Some where I need - $name_array=substr($name_arrary, 0, -4); - ?
2/ How do I write the values to be uploaded ? ( blaw did an example but I am not sure how it worked ).
3/ Do I need to unset the session or something ?
4/ I am sure there was something else but I cant think what it was.
Thanks Anthony
|

03-27-04, 09:24 AM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Remembered
I have just remembered what the other thing was.
With the second script above it :
1/ Puts 5 lots of forms if there is any data to input or not - would be good if it only showed the ones with a value in $name_array.
Sorted this one 2/ It also would be nice to have one on the screen at a time and when you pressed submit it went to the next.
3/ Also I CANT submit the details !!!!!
Do not want a lot do I ?
Anthony
Last edited by Bonzo; 03-27-04 at 09:30 AM.
|

03-27-04, 10:49 AM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
3/ Above
This is sort of working OK - the problem is that when the page loads it sends the data it has - name in this case - to the databas before I can input any more details.
Anthony
|

03-27-04, 11:04 AM
|
 |
Community VIP
|
|
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
|
|
Quote:
|
I blame NeverMind for this problem LOL
|
well, after you read the following lines, you will blame me more
Quote:
|
1/ When I upload the variables to this table and Mysql I want "image" not "image.jpg". Some where I need - $name_array=substr($name_arrary, 0, -4); - ?
|
yes, but if it was an array simply use foreach()
Quote:
|
3/ Do I need to unset the session or something ?
|
no need for that, because once the browser is closed the session is destroyed ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
|

03-27-04, 02:28 PM
|
 |
Coding Addict
|
|
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Diving me MAD
I am on the one step forward about 5 steps back stage at the moment.
The script above creats a table which when submitted adds the data to the database.
It gets the name_array from a session and works OK.
There are up to 5 items in the array ( current setting ) and so I have it set to loop through the actual qty of items creating tables.
Problem :It puts all the tables on the same page but only updates the one when submit pressed !!
I have tried all sorts of things without sucess; can anyone help me out ?
Anthony
P.S. I dont know what I would do without you NeverMind - notice I am using one of your sugestions here. I could not get the foreach to work though.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
|
Getting Rated
|
relledge |
Announcements |
0 |
06-07-03 04:55 PM |
|