capturing photo name for insertion into mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

capturing photo name for insertion into mysql

Post by sleepydad »

I have created a database with a table column that I've named 'photo'. Ultimately what I'm looking to do is offer my users the option to upload photos to a folder, capture that photo name and insert that name into the photo column of my table. Currently my HTML reads (abbreviated):

<form action='process.php' method='post'>
<input type="file" name="photo">
</form>

I've tried in my php using:

$path="images/";
$photo=basename($_FILES['photo']);
$photo=$path.$photo;

All that inserts into the database is the "images/". The photo name is stripped away, or never captured at all.

Solution(s)??

Thanks in advance -
sleepydad
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: capturing photo name for insertion into mysql

Post by John Cartwright »

What does

Code: Select all

echo '<pre>';
print_r($_FILES);
echo '</pre>';
reveal after an upload?
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Re: capturing photo name for insertion into mysql

Post by sleepydad »

Thank you John. That resulted in:

Array
(
[photo] => Array
(
[name] => cut.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpGQZ1uk
[error] => 0
[size] => 6155
)

)

Now how do I 'grab' [name]. Sorry, I'm pretty new to php.

Thanks again -
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: capturing photo name for insertion into mysql

Post by John Cartwright »

Code: Select all

echo $_FILES['photo']['name'];
:)
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Re: capturing photo name for insertion into mysql

Post by sleepydad »

Cool. That got the file name. One more question, and I promise I'll leave you all alone (for today anyway!) ..

When I hit the submit button, it prints the print_r() in the browser window. Any way to suppress that so my visitors don't have to see it, yet still maintain the functionality that we've acheived?
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Re: capturing photo name for insertion into mysql

Post by sleepydad »

Hey! Figured something out on my own!

$photoName=($_FILES['photo']['name']);

Thanks again, John, for the assistance.

sleepydad
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: capturing photo name for insertion into mysql

Post by John Cartwright »

You can remove the echo '<pre> print_r stuff. That was strictly for debugging purposes.
Post Reply