Jump to content

Recommended Posts

Hi:

thank you for the reply.

The thing is, I do not want to allow anyone to download the files. If they are in a folder, then everyone can download them, while if it is in a db, then I can decide who can download what.

 

I want to be able to upload the following files:

zip files

images

movies

 

Thank you

Sp alright, here is the code I have so far:

 

Upload form

<form action="http://localhost/admin.php?page=gallery&mode=up&folder=image&sub=add&action=cont" method="post" enctype="multipart/form-data" name="upload">
<table width="30%" cellpadding="1" cellspacing="1" align="center">

<tr><td with="40%" bgcolor="BCD7B8" align="right">
    <b>Image Name:</b>
</td><td width="60%" bgcolor="D4EFD0">
    <input type="text" name="download_name" value="**FILE NAME**">
</td></tr>

<tr><td bgcolor="BCD7B8" align="right">
    <b>Gallery:</b>
</td><td bgcolor="D4EFD0" align="left">
   <select name="id">
    <?php
    // Connect to db
    $query = "SELECT name, id FROM `user_file` WHERE type = 'gall'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result))
    {
        $id = $row["id"];
        $name = $row["name"];
    
    ?>
        <option value="<?php echo("$id");?>"><?php echo("$name");?></option>
    <?php
    }
    mysql_close();
    ?>
     </select>
</td></tr>

<tr><td bgcolor="BCD7B8" align="right">
    <b>File:</b>
</td><td bgcolor="D4EFD0" align="left">
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000000">
    <input name="userfile" type="file" class="box" id="userfile">
</td></tr>

<tr><td bgcolor="BCD7B8">
</td><td bgcolor="D4EFD0" align="center">
   <input type="submit" name="upload" value="Upload">
</td></tr></table></form>

 

and here is the PHP Code

<?php
$download_name = $_POST["download_name"];
$id = $_POST["id"];
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'rb');
$content = fread($fp, fileSize);
$content = addslashes($content);
fclose($fp);
// Connect to db
$query = "INSERT INTO upload (name, size, type, content, download_name, type_id ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$download_name', '$id')";

mysql_query($query) or die('Error, query failed'); 

header("location: http://localhost/admin.php?page=gallery&mode=up&folder=image&sub=add&action=done");
?>

 

the problem with this is that everything works fine but the content is only "[blob - 0b]". Why? I mean the info (size/name/...) everything else is uploaded!

What do you mean by "apart from"? What is wrong with

$content = addslashes($content);

 

?

And why shouldn't the blob be more than 0 bytes?

 

And is this how you view a file?


// Connect to db
$query = "SELECT name, type, size, content, download_name " .
         "FROM upload WHERE id = '23'";

$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
echo("$content");
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;

 

 

sorry, ok the code works, but I get to download the file! This is an image file and I want to be able to display it! How can I disply the file?

 

EDITED: actually the code does not work at all! I mean I downloaded something, but it is nothing! I mean it actually is 0bytes!

 

humm, the code looks ok, so unless the DB is wrong i can' think why your having problems as for the addslahes i personal encode the data first..

 

are the sizes etc being stored correctly ?

 

also i assume the file is under 16mb and the contents is a "MEDIUMBLOB"

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.