Jump to content

Archived

This topic is now archived and is closed to further replies.

XxDeadmanxX

Help with image uploader

Recommended Posts

Ok im making website where users can upload images,videos and music but what i dont know how to grab the username that uploaded something and i want the username and file to go to database.

Here is the code i dont know why it doesnt work.

[code]<?php
$reqlevel = 1;
include("membersonly.inc.php");


//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')"; 
$result = mysql_query($query);
}

include("upload_form.php");

if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>n";
}
}

include("list_images.php");

?>[/code][color=black][/color]

Share this post


Link to post
Share on other sites
I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.

Share this post


Link to post
Share on other sites
[quote author=freakus_maximus link=topic=112843.msg458187#msg458187 date=1161888540]
I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.
[/quote]
$user_currently_loged shows the user login so when i put it in there it should of grabed the username and put it in database but it didnt.

Share this post


Link to post
Share on other sites
Humm I think we are confused? I would store the logged in username in a session.

session_register("current_username");
$current_username = $user_currently_logged;

Then simply do a mysql query:

$sql = "INSERT into thetable (username) VALUES ($_SESSION['current_username']) WHERE someclause";
mysql_query($sql) or die(mysql_error());

Share this post


Link to post
Share on other sites
[quote author=JustinK101 link=topic=112843.msg458194#msg458194 date=1161888919]
Humm I think we are confused? I would store the logged in username in a session.

session_register("current_username");
$current_username = $user_currently_logged;

Then simply do a mysql query:

$sql = "INSERT into thetable (username) VALUES ($_SESSION['current_username']) WHERE someclause";
mysql_query($sql) or die(mysql_error());
[/quote]
So  Your saying like this.
[code]<?php
$reqlevel = 1;
include("membersonly.inc.php");


//print_r($_POST);

if($_POST["action"] == "Upload Image")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}
$sql = "INSERT into thetable (username, file) VALUES ($_SESSION['current_username'],$imagename) WHERE someclause";
mysql_query($sql) or die(mysql_error());
}

include("upload_form.php");

if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>n";
}
}

include("list_images.php");

?>[/code]

Share this post


Link to post
Share on other sites
[quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]
WOW 30+ views and only 5 posts.
[/quote]

1 good reply is all you need.

If the message title were more meaningful, instead of just a "help me" then more people might think "I can probably help with that".

See forum guidelines

Share this post


Link to post
Share on other sites
[quote author=Barand link=topic=112843.msg458218#msg458218 date=1161890737]
[quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]
WOW 30+ views and only 5 posts.
[/quote]

1 good reply is all you need.

If the message title were more meaningful, instead of just a "help me" then more people might think "I can probably help with that".

See forum guidelines
[/quote]That didnt help me

Share this post


Link to post
Share on other sites
It was not meant to help directly. I was telling you to read the guidelines and use meaningful topic titles.

Also, have you considered that the 25+ who didn't post may be waiting for your answers to the questions posed by Freakus?

Again, read the guidelines. If someone is trying to help but needs more info, it's in your interests to provide that extra info.
[quote author=freakus_maximus link=topic=112843.msg458187#msg458187 date=1161888540]
I'm taking it that your included members script is what is populating this variable:

$user_currently_loged

If not, then how is getting passed, in a session? hidden field? etc..

Also, is that the correct name for the variable? Just not sure if 'loged' should be 'logged' maybe.

Post some additional code showing how that variable is initially being set and then passed to this page.
[/quote]

Share this post


Link to post
Share on other sites
It looks like you have an extra double quote in with your values.

Try changing this ->

[code]$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')";  
$result = mysql_query($query);[/code]

to this ->

[code]$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')";  
$result = mysql_query($query);[/code]

As a side note, you do realize that a broad range of users come here to find help and give help. You may have a lot of views because people are looking for solutions to similar problems. Try a be a little more patient with the time it may take for someone to give their time freely to help you.Barand is probably one of the best resources you could have help you, but your lack patience can put people off.

Anyways, hopefully that fixed your problem.

Share this post


Link to post
Share on other sites
[quote author=freakus_maximus link=topic=112843.msg458251#msg458251 date=1161893981]
It looks like you have an extra double quote in with your values.

Try changing this ->

[code]$query = "INSERT INTO Img (username, file) VALUES ("'$user_currently_loged','$imagename')";  
$result = mysql_query($query);[/code]

to this ->

[code]$query = "INSERT INTO Img (username, file) VALUES ('$user_currently_loged','$imagename')";  
$result = mysql_query($query);[/code]

As a side note, you do realize that a broad range of users come here to find help and give help. You may have a lot of views because people are looking for solutions to similar problems. Try a be a little more patient with the time it may take for someone to give their time freely to help you.Barand is probably one of the best resources you could have help you, but your lack patience can put people off.

Anyways, hopefully that fixed your problem.
[/quote]
Thanks man

Share this post


Link to post
Share on other sites
[quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]
WOW 30+ views and only 5 posts.
[/quote]

Just because you have 30+ views doesn't mean the people who look at it know how to help ;)  I go through alot of posts to see if I can help and sometimes I can't *shrug*

Share this post


Link to post
Share on other sites
[quote author=SharkBait link=topic=112843.msg459530#msg459530 date=1162139174]
[quote author=XxDeadmanxX link=topic=112843.msg458193#msg458193 date=1161888897]
WOW 30+ views and only 5 posts.
[/quote]

Just because you have 30+ views doesn't mean the people who look at it know how to help ;)  I go through alot of posts to see if I can help and sometimes I can't *shrug*
[/quote]
LOL i understand like 2 people told me.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.