Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-25-2004, 02:23 AM   #1 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
php script that can upload binary data

Can someone share a script to me that have the ff capabilities?

1. Allow users to upload an Image File.
2. The uploaded File will be stored in my MySQL Database
3. They will be able to delete a File if they want to.

TIA

Last edited by infinite_root; 08-25-2004 at 03:03 PM.
infinite_root is offline   Reply With Quote
Old 08-25-2004, 04:51 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
That's asking a lot.

Were you able to at least get the data in mysql from the other `binary upload` thread?

3 - Need to either have GD compiled with php, or the server needs some external image tools. (ie: imagemagic or netpbm)

4 - Url for each file? You would need a php script as a the URL which would fetch the image and pass it through to the browser.

5 - fairly easy - just run a delete query as you normally would.

-r
idx is offline   Reply With Quote
Old 08-25-2004, 05:48 AM   #3 (permalink)
sammy
Code Monkey
 
sammy's Avatar
 
Join Date: Jun 2004
Location: Brooklyn/Rochester
Posts: 53
sammy is on a distinguished road
Send a message via AIM to sammy
I did a project where I was uploading binary files. The file didnt actually get stored in the database (we used Oracle). We hashed the filename, creating a unique name, stored the file on the filesystem under that name and put the file names in the database.

It also seems that your making a picture gallery. There are alot of picture gallery code out there.

Check out HotScripts.com

Hot Scripts - Image galleries

Theres a script called Picture Scroller, it seems to fit your needs, and you can always modify it to do whatever you want.
__________________
sammy is offline   Reply With Quote
Old 08-25-2004, 11:44 PM   #4 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Quote:
Originally posted by sammy
I did a project where I was uploading binary files. The file didnt actually get stored in the database (we used Oracle). We hashed the filename, creating a unique name, stored the file on the filesystem under that name and put the file names in the database.
Hi Sammy,

Yes, that's what I need. Having the files stored in the database and files on the machine filesystem.

Could you possibly share them with me? Pls.

Thanks.
infinite_root is offline   Reply With Quote
Old 08-26-2004, 04:27 AM   #5 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Hi,

I made a script to accomplish the following it works with Apache under windows however on my production server running Apache in Linux it had some errors

I am running php-4.3.8-1, Apache 2.0.50-1 and Mysql-4.8.20-1

My db structure:
mysql> CREATE TABLE image (
> id_files tinyint(3) unsigned NOT NULL auto_increment,
> bin_data longblob NOT NULL,
> description tinytext NOT NULL,
> filename varchar(50) NOT NULL,
> filesize varchar(50) NOT NULL,
> filetype varchar(50) NOT NULL,
> PRIMARY KEY (id_files)
> );


Here's the code:

Code:
<?php
if ($action == "upload") {
  // upload data and insert it into the db now
  include "open_db.inc";

  if (isset($binFile) && $binFile != "none") {
    $data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
    $strDescription = addslashes(nl2br($txtDescription));
    $sql = "INSERT INTO image ";
    $sql .= "(description, bin_data, filename, filesize, filetype) ";
    $sql .= "VALUES ('$strDescription', '$data', ";
    $sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
    $result = mysql_query($sql, $db);
    mysql_free_result($result); // clean up!
    echo "Thank you. The new file was successfully added to our database.<br><br>";
    echo "<a href='main.php'>Continue</a>";
  }
  mysql_close();

} else {
?>
<HTML>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
 <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
 <INPUT TYPE="hidden" NAME="action" VALUE="upload">
 <TABLE BORDER="1">
  <TR>
   <TD>Description: </TD>
<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
  </TR>
  <TR>
   <TD>File: </TD>
   <TD><INPUT TYPE="file" NAME="binFile"></TD>
  </TR>
  <TR>
   <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
  </TR>
 </TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
Running this script gives an error as follows:


Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/httpd/htdocs/works/add.php on line 14
Thank you. The new file was successfully added to our database.


I can view the file being uploaded though. But the error confuses me.

How can I eliminate it? Any help will be greatly valued.

Thanks

Last edited by infinite_root; 08-26-2004 at 04:54 AM.
infinite_root is offline   Reply With Quote
Old 08-26-2004, 04:59 AM   #6 (permalink)
sammy
Code Monkey
 
sammy's Avatar
 
Join Date: Jun 2004
Location: Brooklyn/Rochester
Posts: 53
sammy is on a distinguished road
Send a message via AIM to sammy
seems to me that your mysql_query COULD be returning false ... can you print it out and see if that is the case?
__________________
sammy is offline   Reply With Quote
Old 08-26-2004, 06:17 PM   #7 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Quote:
Originally posted by sammy
seems to me that your mysql_query COULD be returning false ... can you print it out and see if that is the case?
I can view the uploaded files listed in the query:

SELECT * FROM 'tbl_Files'


However, viewing the image provides "garbage" character instead of the picture image i desired.

What could be wrong?

TIA

Last edited by infinite_root; 08-26-2004 at 07:32 PM.
infinite_root is offline   Reply With Quote
Old 08-26-2004, 08:14 PM   #8 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Its what I mentioned in the other thread. Don't use addslashes on your binary data.

-r
idx is offline   Reply With Quote
Old 08-26-2004, 09:09 PM   #9 (permalink)
infinite_root
Registered User
 
infinite_root's Avatar
 
Join Date: Apr 2004
Posts: 26
infinite_root is on a distinguished road
Quote:
Originally posted by idx
Its what I mentioned in the other thread. Don't use addslashes on your binary data.

-r
But removing addslashes doens't give any result? No result at all!
infinite_root is offline   Reply With Quote
Old 08-27-2004, 06:03 PM   #10 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
So it doesn't store the file when you remove addslashes ?

Quote:
However, viewing the image provides "garbage" character instead of the picture image i desired.
If you can still view the garbage, then it might just be a display issue. I don't have a good example onhand, but typically you would need to create a php page which pulls and displays the image itself.. (not sure how you're viewing it)

eg:
Code:
<img src="view_pic.php?id=4" border=0>
So the view_pic.php file would perform a query (fetching the row data for row ID 4), send a header so the browser knows its an image and echo the garbage content..

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP ban IP range script Boks PHP 23 05-21-2008 03:07 AM
Loading Binary Data infinite_root PHP 2 08-23-2004 10:14 PM
sending POST multiple post requests in one php script. sde PHP 2 08-09-2003 05:10 PM
Passing form data to PHP with Javascript bdl PHP 5 07-03-2002 10:18 AM


All times are GMT -8. The time now is 05:01 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting