Jump to content

upload script question


Reaper0167

Recommended Posts

i found this basic upload script. it works, very simple. but when the picture is uploaded to mysql,,, it creates its own row,, a new row... how would i have it upload to the row of whoever is signed in at that time? here is the simple little script i found online. also,,, what is the "rb" in the line below??

<?php
$filename = $_FILES['file']['tmp_name'];
if (($handle = fopen($filename, "rb"))) {             // rb????
$stream = fread($handle, filesize($filename));
fclose($handle);
unlink($filename);
$type = $_FILES['file']['type'];

$dbh = mysql_connect("---------", "----------", "----------");
mysql_select_db("--------", $dbh);

$qstr = sprintf("INSERT INTO `members` (`type`, `stream`) VALUES ('%s', '%s')",
mysql_real_escape_string($type),
mysql_real_escape_string($stream));
echo "Picture added to database.";
mysql_query($qstr, $dbh) or die(mysql_error());
}
?>

better yet,,, instead of uploading the image in the same row of the user that is signed in. Would it be better to create a new table for all the images and then somehow link images to users that upload them.. Can i do that???

Link to comment
Share on other sites

read this please , remember uploading files can cause hack attack,

must specify the correct file. extension allowed to be uploaded.

 

http://uk3.php.net/manual/en/features.file-upload.post-method.php

 

yes create a new database field called pictures

 

example ((database normalization helps.))

 

database field name.

pictures

 

id int not null auto_increment primary key

users_id int not null <<<match this the same as the users login database id name.

picture_name varchar(100) not null

date_added int not null

 

Link to comment
Share on other sites

Could anyone point me in the right direction for a decent upload script. And then also linking a member back to what he/she uploaded. After a user uploads some pictures(picture, name, description of pic), they could go to a page to see just what they uploaded. Or they could also just view all the pics that all the users uploaded. Is this just way to difficult to do....When a user uploads a picture they get to pick from a list of categories that the picture would go in.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.