473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Handling Multiple File Uploads into Database with single INSERT INTO???

jenkinsloveschicken
I am developing a administrative backend for our sales dept website. They are using admin forms to manipulate what is displayed for the end user on the site. I am running into a problem with a form design. The admin user needs to be able to assign both an image and a corresponding PowerPoint/Word/etc document to be downloaded once the end-user selects it.

I am able to get the image in and out of the database no problem, but I am not able to get the ppt to upload.

My submission form code is as follows(ugly I know, will clean up once I get it to work :P)

<div id="Layer1">
<form enctype="multipart/form-data" action=".../mxaddi_uc.php" method="post">
<div id="Layer3" style="font-family:'Trebuchet MS'">
<h4><font color="#FFFFFF" size="2">Please enter the title</font></h4>
</div>
<input type="text" name="title" value="" maxlength="120" width="30"/>
<br />
<h4><font color="#FFFFFF" size="2" style="font-family:'Trebuchet MS'">Please enter the contest description</font></h4>
<textarea name="description" rows="3"></textarea><br />

<div id="Layer2" style="font-family:'Trebuchet MS'">
<h4><font color="#FFFFFF" size="2">Please select image file to upload</font></h4>
</div>
<p>&nbsp;</p>
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
</p>
<p>
<input name="userfile" type="file" />
</p>

<h4><font color="#FFFFFF" size="2" style="font-family:'Trebuchet MS'">Please select presentation file to upload</font></h4>
<p>
<input name="presentationfile" type="file" />
</p>
<p>
<input name="submit" type="submit" value="Submit" />
</p>

</form>
</div>

The receiving form code is as follows:

<?php
session_start();
require ('dbconfig.php');
$login = false;
$link = mysql_connect('localhost', $dbuser, $dbpass);
$dbname = 'mydb';
$db_selected = mysql_select_db($dbname, $link);

$title = $_POST['title'];
$description = $_POST['description'];

$presentationFileName = addslashes (file_get_contents($_FILES['presentationfile']['tmp_name']));

$imgFileName = addslashes (file_get_contents($_FILES['userfile']['tmp_name']));

$stamp = mktime(date("h"), date("m"), date("s"), date("m"), date("d"), date("Y"));


$inc_update = "INSERT INTO MAX_Incentive (AutoID, MMI_heading, MMI_content, MMI_description, MMI_presentation) values ('$stamp', '$title', '$imgFileName', '$description', '$presentationFileName')";
$updatemov = mysql_query($inc_update);

?>

-$imgFileName is longblob data type
-$presentationFileName is longblob data type

This is new territory for me, I'm usually strictly data and reporting pages, but I have been tasked with re-writing this system. I would really appreciate if some of you gurus could lend a n00b a hand.

Thanks in advance,

Jenkins
Jan 15 '08 #1
6 4396
MarkoKlacar
296 Expert 100+
Hi,

from looking at your code it seems you don't get the file (ppt) only the name.
Other than that I can't see any major flaws.

Can you try getting the file content for the ppt and let us know?

Cheers
Jan 15 '08 #2
Markus
6,050 Expert 4TB
Please read the forum posting guidelines

Use code tags!

It makes things easier for us to read; if things arent easy to read we're not going to take the time to sit here and decipher it.
Jan 15 '08 #3
Re-posting with code tags:
Expand|Select|Wrap|Line Numbers
  1. <div id="Layer1">
  2. <form enctype="multipart/form-data" action=".../mxaddi_uc.php" method="post">
  3. <div id="Layer3" style="font-family:'Trebuchet MS'">
  4. <h4><font color="#FFFFFF" size="2">Please enter the title</font></h4>
  5. </div>
  6. <input type="text" name="title" value="" maxlength="120" width="30"/>
  7. <br />
  8. <h4><font color="#FFFFFF" size="2" style="font-family:'Trebuchet MS'">Please enter the contest description</font></h4>
  9. <textarea name="description" rows="3"></textarea><br />
  10.  
  11. <div id="Layer2" style="font-family:'Trebuchet MS'">
  12. <h4><font color="#FFFFFF" size="2">Please select image file to upload</font></h4>
  13. </div>
  14. <p>&nbsp;</p>
  15. <p>
  16. <input name="userfile" type="file" />
  17. </p>
  18.  
  19. <h4><font color="#FFFFFF" size="2" style="font-family:'Trebuchet MS'">Please select presentation file to upload</font></h4>
  20. <p>
  21. <input name="presentationfile" type="file" />
  22. </p>
  23. <p>
  24. <input name="submit" type="submit" value="Submit" />
  25. </p>
  26.  
  27. </form>
  28. </div>
  29.  
  30.  
The receiving form code is as follows:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. require ('dbconfig.php');
  4. $login = false;
  5. $link = mysql_connect('localhost', $dbuser, $dbpass);
  6. $dbname = 'mydb';
  7. $db_selected = mysql_select_db($dbname, $link);
  8.  
  9. $title = $_POST['title'];
  10. $description = $_POST['description'];
  11.  
  12. $presentationFileName = addslashes (file_get_contents($_FILES['presentationfile']['tmp_name']));
  13.  
  14. $imgFileName = addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
  15.  
  16. $stamp = mktime(date("h"), date("m"), date("s"), date("m"), date("d"), date("Y"));
  17.  
  18.  
  19. $inc_update = "INSERT INTO MAX_Incentive (AutoID, MMI_heading, MMI_content, MMI_description, MMI_presentation) values ('$stamp', '$title', '$imgFileName', '$description', '$presentationFileName')";
  20. $updatemov = mysql_query($inc_update);
  21.  
  22. ?>
  23.  
Again, MMI_content and MMI_presentation are longblob data types in the table. In response to the first reply, I am getting the actual image into the database using the same method as the ppt. I'm just not sure what the difference is, or if there is a technical limitation on this action. I have researched php.net and others, and all point back to the syntax I am using.



Any insight would be great!

Thanks,
Jenkins
Jan 15 '08 #4
MarkoKlacar
296 Expert 100+
Hi,

do you get any error messages, the code looks fine to me (maybe I'm blind...).
Jan 16 '08 #5
Well not sure at this point. I have tried a different method as I checked my php.info script and all of the allotted file size related settings are correct. I was able to load ppt files that were below 512kb and write them to my server. I think I have isolated the problem to the LimitRequestBody setting of the php.conf file in the httpd directory. I am working with my local IT on this. Hopefully they will find a solution.

In the meantime, I have tried my hand at just parsing the file and writing it directly to the server without the db intervention with varying degrees of success. My goal is not to have to deal with server file permissions so that this system can function in a more autonomous fashion as I will be leaving this company in the next few months.

My line of thinking is to just create a single record and store the BLOB data associated with each sales contest/incentive entry added. This way the sales personnel can directly control the content of their pages without me having to worry about my app having to worry about file permissions on the server.

I may be overthinking this or not thinking it through enough. This isn't usually my bag of tea, but our local programmers have some resource constraining projects right now and I decided to lend some help. Most of my stuff is table based reporting, data parsing, limited automation, etc.

I am more or less looking for direction to take at this point if any of you more experienced guys have any ideas.

Thanks for all the time and consideration.

BTW: Here is some updated code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. session_start();
  4. require ('dbconfig.php');
  5. $login = false;
  6. $link = mysql_connect('localhost', $dbuser, $dbpass);
  7. $dbname = 'sprint-tech';
  8. $db_selected = mysql_select_db($dbname, $link);
  9.  
  10.     $title = $_POST['title'];
  11.     $description = $_POST['description'];
  12.  
  13.     if (isset($_FILES['userfile'])) {
  14.  
  15.         $imgFileName = addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
  16.         }
  17.         else
  18.         {
  19.         $imgFileName = '';
  20.         }
  21.  
  22.  
  23.     $presentationFileName = addslashes (file_get_contents($_FILES['presentationfile']['tmp_name']));
  24.     $presentationFileType = $_FILES['presentationfile']['type'];
  25.  
  26.     if ($presentationFileType <> '') {
  27.  
  28.         switch ($presentationFileType) {
  29.             case "application/vnd.ms-powerpoint":
  30.                 $fileExt = ".ppt";
  31.                 break;
  32.             case "application/msword":
  33.                 $fileExt = ".doc";
  34.                 break;
  35.             case "application/vnd.ms-excel":
  36.                 $fileExt = ".xls";
  37.                 break;
  38.                 }
  39.             }
  40.  
  41.     $stamp = mktime(date("h"), date("m"), date("s"), date("m"), date("d"), date("Y"));
  42.     $fileName = $stamp . $fileExt;
  43.  
  44.     $createVar = file_put_contents("documents/$fileName", "$presentationFileName");    
  45.     echo $fileName;
  46.  
  47.     $inc_update = "INSERT INTO MAX_Incentive (AutoID, MMI_heading, MMI_content, MMI_description, MMI_presentation, MMI_prestype, MMI_ext) values ('$stamp', '$title', '$imgFileName', '$description', '$presentationFileName', '$presentationFileType', '$fileExt')";
  48.     $updatemov = mysql_query($inc_update);
  49.  
  50.  
  51. ?>
  52.  
  53.  
-Jenkins
Jan 17 '08 #6
Please close this thread. I have changed the method of handling the file uploads.

-Jenkins
Jan 17 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
2
by: hartley_aaron | last post by:
Hi, I have an application running on a wireless device and being wireless I want it to use bandwidth as efficiently as possible. Therefore, I want the SQL statement that it uploads to the SQL...
10
by: David | last post by:
Hello I am trying to collect errors and record them in a table instead of a popup message stopping my code. It seems to work ok, but when I try to add ERR.Description to my code it fails on Syntax...
3
by: darrel | last post by:
My understanding is that using the FILE form element to allow a file upload is limited to one unique file per page. Is that correct? Any thoughts on how best to design an interface to allow...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
4
by: yehaimanish | last post by:
I am developing the project management system. Each Project: 1. Title, description ... , stored in mysql database 2. Upto ten files (initial description), (name in db, file in file system) 3....
9
by: Jankie | last post by:
<?php if(isset($_POST) && $_FILES > 0){ foreach ($_FILES as $key => $error) { $name = $_FILES; $tempname = $_FILES; ………… ……… $path = 'uploads/'; include 'dbcon.php'; $rep = strpos($_FILES,...
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.