/    Sign up×
Community /Pin to ProfileBookmark

uplaod image/store path in database

I want to upload 20 images for each member and store the filepaths in a databse alongwith their other details.
I have tried out some image upload scripts but I am not able to insert the path in the table.Can anyone pls help.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJan 22.2005 — [i]Originally posted by ashokvas [/i]

[B]I am not able to insert the path in the table.Can anyone pls help. [/B][/QUOTE]

Are you talking about the original path that the file had on the visitor's machine? ...or, the path under which you save the file on the server?
Copy linkTweet thisAlerts:
@ashokvasauthorJan 22.2005 — I want to save it in a specific folder under any name (like a timestamp or any name that we chose to give it).

I hope I have been able to answer your question
Copy linkTweet thisAlerts:
@phpnoviceJan 23.2005 — Well, the following is an example I got from the [url=http://us2.php.net/get/php_manual_chm.zip/from/a/mirror]us2.php extended php manual[/url].

(Sorry, I couldn't get this site to not break the IF statement in the wrong place.)
[code=php]<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of
// $_FILES. In PHP earlier then 4.0.3, use copy() and is_uploaded_file()
// instead of move_uploaded_file

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir. $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile)) {
print "File is valid, and was successfully uploaded. ";
print "Here's some more debugging info:n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:n";
print_r($_FILES);
}
print "</pre>";

?>[/code]

This will move the uploaded file from the temp area to the path you specify. Do you already have code like this?
Copy linkTweet thisAlerts:
@ashokvasauthorJan 23.2005 — Thanks.But I am having problem inserting the filename in the database.Also what to do for

1)I want to name the file with a new name,using a fixed name,like 'photo1' or 'photo2'....

2)If I dont like the photo uploaded to 'photo1' location earlier,then I should be able to upload another photo to that location and overwrite the earlier image file.

Thanks a ton!!
Copy linkTweet thisAlerts:
@phpnoviceJan 23.2005 — [i]Originally posted by ashokvas [/i]

[B]I am having problem inserting the filename in the database.[/B][/QUOTE]

Show the code you're attempting to use to insert the file name into the database.
Copy linkTweet thisAlerts:
@ashokvasauthorJan 24.2005 — Here is the code

[code=php]<?php
include ("access_user_class.php");

$page_protect = new Access_user;
// $page_protect->login_page = "login.php"; // change this only if your login is on another page
$page_protect->access_page(); // only set this this method to protect your page

if (isset($_GET['action']) && $_GET['action'] = "log_out") {
$page_protect->log_out(); // the method to log off
}
include ("upload_class.php"); //classes is the map where the class file is stored (one above the root)
include("mysql_connectinfo.inc");
$max_size = 1024*100; // the max. size for uploading
echo "Welcome ".$_SESSION['user']." !";
echo "Welcome ".$_SESSION['pw']." !";
$my_upload = new file_upload;

$my_upload->upload_dir = "images/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".png",".gif",".jpg", ".zip"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 100; // change this value to fit your field length in your database (standard 100)


if(isset($Submit)) {
$my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
$my_upload->the_file = $_FILES['upload']['name'];
$my_upload->http_error = $_FILES['upload']['error'];
$my_upload->replace = "y"; // because only a checked checkboxes is true
$my_upload->rename_file = "true";
$my_upload->do_filename_check = (isset($_POST['check'])) ? $_POST['check'] : "n"; // use this boolean to check for a valid filename
$my_upload->upload();
// use the following if clause to do something if the upload is true
if ($my_upload->upload()) { $src_filename="images/".$this->file_copy ;
$sql = "UPDATE users SET foto1 = '$src_filename' WHERE pw = $_SESSION['pw'] AND login=$_SESSION['user']";

$result = @mysql_query( $sql ) or die("Error inserting record: " . mysql_error());


}
}[/code]

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Upload example</title>

</head>

<body><img src="<?php echo $src_filename;?>"/>

<h3>File upload script:</h3>

<p>Max. filesize = <?php echo $max_size; ?> bytes.</p>

<form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $PHP_SELF; ?>">

<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_size; ?>">

<input type="file" name="upload" size="30"><br>

Replace ? <input type="checkbox" name="replace" value="y"><br>

Validate filename ?

<input name="check" type="checkbox" value="y" checked>

<input type="submit" name="Submit" value="Submit">

</form>

<p><?php echo $my_upload->show_error_string(); ?></p>

</body>

</html>


I am using two classes here-one is 'access_user' which is for user login and authentication.Other is 'upload class' for uplaoding images.

The image gets uploaded but no update of database.

Thanks once again
Copy linkTweet thisAlerts:
@phpnoviceJan 24.2005 — This statement:

$sql = "UPDATE users SET foto1 = '$src_filename' WHERE pw = $_SESSION['pw'] AND login=$_SESSION['user']";

needs to at least be changed to this:

$sql = "UPDATE users SET foto1 = '{$src_filename}' WHERE pw = '{$_SESSION['pw']}' AND login = '{$_SESSION['user']}';";
×

Success!

Help @ashokvas 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.7,
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,
)...