Rank: Newbie
Groups: Member
Joined: 11/13/2009(UTC) Posts: 1
|
Hello, I have just downloaded the trial upload script in the hope of seeing if I can integrate this into my PHP/Mysql website. My knowledge is all self taught and so I am not familiar with indepth programming. Want I want to achieve is when a file is uploaded for example with the Basic Uploader example, I want to add the file name into a database! Eventually I want to add the filenames into a table (photo_gallery) as rows with other details such as the members name, etc! Ive tried to insert into the upload.php page of the basic upload sample along with database connection to see if this would work. Ive tried using an INSERT INTO and UPDATE and neither seem to work. The UPDATE does update the field to nothing so im guessing I havent got the right $variable name of the image. Here is the code I used to update: Code:
/////This is the section taken from upload.php
//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
function getSafeFileName($fileName)
{
global $absGalleryPath;
$newFileName = $fileName;
$j = 1;
while (file_exists($absGalleryPath . "/" . $newFileName))
{
$newFileName = $j . "_" . $fileName;
$j = $j + 1;
}
return $newFileName;
$db_server = "localhost";
$db_username = "db username";
$db_password = "db password";
$db_name = "db name";
$con=mysql_connect($db_server,$db_username,$db_password);
//connection string
mysql_select_db($db_name,$con);
//select db
mysql_query("UPDATE photo_gallery SET photoname='$newFileName' WHERE user='Test' ");
}
//////I have set up a row with the user as test but it doesnt seem to work
saveUploadedFiles();
?>
Any ideas how I can get this to work? Thanks Justin
|
|
|
|
Rank: Advanced Member
Groups: Member
Joined: 5/14/2007(UTC) Posts: 24
Was thanked: 1 time(s) in 1 post(s)
|
Hello Justin, Try to place the return statement to the end of function: Code:
/////This is the section taken from upload.php
//This method verifies whether file with such name already exists
//and if so, construct safe filename name (to avoid collision).
function getSafeFileName($fileName)
{
global $absGalleryPath;
$newFileName = $fileName;
$j = 1;
while (file_exists($absGalleryPath . "/" . $newFileName))
{
$newFileName = $j . "_" . $fileName;
$j = $j + 1;
}
$db_server = "localhost";
$db_username = "db username";
$db_password = "db password";
$db_name = "db name";
$con=mysql_connect($db_server,$db_username,$db_password);
//connection string
mysql_select_db($db_name,$con);
//select db
mysql_query("UPDATE photo_gallery SET photoname='$newFileName' WHERE user='Test' ");
return $newFileName;
}
//////I have set up a row with the user as test but it doesnt seem to work
saveUploadedFiles();
?>
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.