/    Sign up×
Community /Pin to ProfileBookmark

Save array in mysql database

Hi

I created a multi file upload form with save in database using php, javascript and flash.

The form allows users to select & upload multiple files using flash. The files are then sent to the server and saved to the database using php.

My problem is. The files are uploaded to the server OK. but stores array in the database eg

If uploades-

img01.jpg
img02.jpg

stores as in database-
array
array

Help!
CODE BELOW-

<?php
session_start();

echo ‘Upload result:<br>’;

$uploaddir = ‘userUploads/’;
$uploadfile = $uploaddir . basename(rand(1, 4000) . $_FILES[‘Filedata’][‘name’]);

echo ‘<pre>’;
if (move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], $uploadfile)) {
echo “File is valid, and was successfully uploaded.n”;
$uploadedfiles = ($_
FILES);
} else {
echo “Possible file upload attack!n”;
}

$files[] = $uploadedfiles;
foreach($files as $value)
{
$insert = “INSERT INTO testdata (testID, testImg, testImgId) VALUES (‘$testid’, ‘$value’, ‘$Idnum’)”;
mysql_select_db($database_img_conn, $img_conn);
mysql_query($insert) or die(mysql_error());
}
?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chazzySep 12.2008 — when you do
[code=php]
$files[] = $uploadedfiles;
[/code]

You're telling PHP to add to the array named $files at index 0 the contents of $uploadedfiles. so $value is essentially $uploadedfiles. Instead, just change that line to
[code=php]
$files = $uploadedfiles;
[/code]

And it should behave as you want.
Copy linkTweet thisAlerts:
@ReverendAlGreenSep 12.2008 — Try this, replace

$insert = "INSERT INTO testdata (testID, testImg, testImgId) VALUES ('$testid', '$value', '$Idnum')";

with

$insert = "INSERT INTO testdata (testID, testImg, testImgId) VALUES ('$testid', '".$value['Filedata']['name']."', '$Idnum')";
×

Success!

Help @kris246 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...