Page 1 of 1

Getting just a filename from upload

Posted: Fri Jul 26, 2002 10:26 am
by spear1976
Hi,

Again I'm working on my small joke DB, and for every thing i figure out, i realize that there is twice as much i don't understand.
But, I'm getting closer..

I have managed to implement:
http://www.zend.com/zend/spotlight/uploading.php

It now accepts uploads, and everything i registered in my mySQL DB.
It add the record, and my "show_joke.php" page, checks if there is an Image attached, and displays it, if no picture is included, it jumps to the next part of the script.

What I can't figure out is how to get the filename only (using the abowe script/link). It saves the 'real' path in my mySQL (E.g: /var/www/html/xxx/upload/945.gif).
Is there a way i can remove the path, and only include the filename when i store it to the DB?

Hope this made sense...

Best regards, Spear

Posted: Fri Jul 26, 2002 10:29 am
by RandomEngy
If you uploaded via POST, the name is in $_FILES['filename']['name'] . The 'filename' in this case is the name you gave the <input type="file"> field.

Still problems with upload/mysql

Posted: Fri Jul 26, 2002 10:47 am
by spear1976
Hi,
RandomEngy wrote:If you uploaded via POST, the name is in $_FILES['filename']['name'] . The 'filename' in this case is the name you gave the <input type="file"> field.
Thank you very much for your quick reply.
I've looked around in my code, and tried lots of different combinations. However if i use '$file1' which is the name in my form, i get the '/tmp/somename' variable.

In the before mentioned script (where i found the upload system), the file is copied to /var/www/html/somepath/uploads/
Here it is given a unique filename like: img3d4167a85fc59.gif

This is the information i managed to save to mySQL trough the $dest variable. But of course my problem still remains, since it is saving the complete 'real path' and not just the filename. Is there a way to break this down?

I hope the question is not to stupid, but I've looked trough the entire code, and can not find anything that will let me just get the filename after it has been moved to it's new destination.

Best regards, Spear

It works ::)

Posted: Fri Jul 26, 2002 12:03 pm
by spear1976
Hi,

Thanks for having the patience to help me out :)
Now everything is working almost they way it should.
My problem was easy to solve, at least until i learn better ways of doing things. Of course i had set the $dest variable to the hard path /var/www/html etc... It was fixed by ( :oops: :oops: ) setting it to uploads/ ... Almost to simple to belive...