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
https://forums.phpfreaks.com/topic/142558-upload-script-question/
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

 

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.

Archived

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

×
×
  • 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.