473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

problem with inserting file name in database

3 New Member
Hi everyone. I appreciate your effort at helping newbies like me. I have the following problems and will appreciate urgent help.

PROBLEM NUMBER 1:
Using PHP and MySQL, I am able to upload picture successfully unto the server but not so with the file name of the picture even though other parameters in my form got inserted successfuly in the database. I have read several posts on this topic including here on this site but I can't get around the problem yet.

PROBLEM NUMBER 2:
I equally need help on limiting file TYPE permitted for upload (gif, jpeg, png ONLY) as well as the file SIZE (not more than 100kb).

PROBLEM NUMBER 3:
To force a resize of all pictures uploaded into a smaller thumbnail size of 20kb and stored this in a seperate folder on the server with a seperate filename on the database.

Below is my current PHP code;

Expand|Select|Wrap|Line Numbers
  1.     <?php 
  2.     if (!isset($_POST['upload'])) 
  3.     { 
  4.     include ("submit_interview_test.php"); //shows form if it's not been posted 
  5.     }
  6.  
  7.     else 
  8.     { 
  9.     if($_FILES['pic']['tmp_name'] == "none") 
  10.     { 
  11.     echo "<b>File not successfully uploaded. Maybe check the filesize limit.</b>"; 
  12.     include ("submit_interview_test.php"); 
  13.     exit(); 
  14.     }
  15.  
  16.     if(!ereg("image",$_FILES['pic']['type'])) 
  17.     { 
  18.     echo "<b>File is not an image - try another file.</b>"; 
  19.     include ("submit_interview_test.php"); 
  20.     exit(); 
  21.     }
  22.  
  23.     else 
  24.     { 
  25.     $uploadDir = 'intervimages/'; 
  26.     $destination = $uploadDir.basename($_FILES['pic']['name']); 
  27.     $temp_file = $_FILES['pic']['tmp_name'];
  28.     include ("processinterview.php");
  29.     if ( move_uploaded_file ($temp_file,$destination) ) 
  30.     { echo '<p>Your file has been successfully uploaded!</p>'; 
  31.     } 
  32.  
  33.     else 
  34.     { echo "Problem with picture upload!"; 
  35.     } 
  36.     } // end of else
  37.  
  38.     } // end of else 
  39.     ?> 
THIS IS my processinterview.php code;

Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.     include_once 'includes/db.php';
  3.     $sql="INSERT INTO interview (interviewer, media_house, category, interview_title, title_rider, personality, interview_body, source, published, temp_file, interview_date, location, interview_intro, date) VALUES ('$_POST[interviewer]','$_POST[media_house]','$_POST[category]','$_POST  [interview_title]','$_POST[title_rider]','$_POST[personality]','$_POST [interview_body]','$_POST[source]','$_POST[published]','$_FILES[temp_file]','$_POST[interview_date]','$_POST[location]','$_POST[interview_intro]',now())";
  4.  
  5.     if (!mysql_query($sql))
  6.     {
  7.     die('Error: ' . mysql_error());
  8.     }
  9.     echo "1 interview record has been successfully added to the database.";
  10.     ?>
AND, this is my form (submit_interview_test.php);

Expand|Select|Wrap|Line Numbers
  1.     <form enctype="multipart/form-data" action="processinterview3.php" method="post">
  2.     <table bgcolor="#ececec" border="0" cellspacing="5">
  3.     <tbody>
  4.     <tr><td>Interview conducted by (Interviewer's Name):</td><td><input size="30"  name="interviewer" type="text" /></td></tr>
  5.     <tr><td>Media house (e.g., Punch):</td><td><input size="30" name="media_house" type="text" /></td></tr>
  6.     <tr><td>Location (e.g., Ibadan or USA):</td><td><input type="text" size="30" name ="location" /></td></tr>
  7.     <tr><td>Interview Category (e.g., Local):</td><td><input type="text" size="30" name   ="category" /></td></tr>
  8.     <tr><td>Interview Personality:</td><td><input type="text"  size="30" name ="personality" /></td></tr>
  9.     <tr><td>Interview Title:</td><td><input type="text"  size="130" name ="interview_title" /></td></tr>
  10.     <tr><td>Title Rider:</td><td><input type="text"  size="130" name ="title_rider" /></td></tr>
  11.     <tr><td>Source (e.g., http://...):</td><td><input size="130" name="source" type="text" /></td></tr>
  12.     <tr>  <td valign="top">Interview Introduction:</td>
  13.     <td><textarea name="interview_intro" rows="3" cols="100"></textarea></td></tr>
  14.     <tr><td>Date of Interview (e.g., 26/09/2009):</td><td><input size="30" name="interview_date" type="text" /></td></tr>
  15.     <tr>  <td valign="top">Interview Main Content:</td>
  16.     <td><textarea name="interview_body" rows="12" cols="100"></textarea></td></tr>
  17.     <tr><td>Add Photo (Jpeg or gif not more than 80KB):</td><td><input type="file" name="pic"/></td></tr>
  18.     <tr><td valign="top">Publish rightaway?</td>
  19.     <td><input type="checkbox" name="published" value="1"> Yes (Leave this if this   Interview is not to be published yet)<br>
  20.     <tr><td>&nbsp;</td><td><input value="Submit Interview" type="submit" name="upload"/><font face="arial" size="1">&nbsp;&nbsp;Please check for any error before you submit</font></td></tr>
  21.     </tbody></table>
Thanks for the trouble pls.
Jan 13 '10 #1
4 2926
dgreenhouse
250 Recognized Expert Contributor
1- $_FILES['pic']['name'] - for the original filename
2- preg_match('/image\/(jpeg|gif|png)/i',$_FILES['pic']['type']) - for the type check
3- $_FILES['pic']['size'] - for the file size
4- I'd use $_FILES['pic']['error'] versus $_FILES['pic']['tmp_name'] to check for no file uploaded
5- For the auto-thumbnail generation, use either the gd image library which is usually enabled on most modern hosting accounts. If not, you'll need to set it up.
You can always adjust the size on display, but the defeats that benefit of having an actual thumbnail.
Jan 13 '10 #2
liberty1
3 New Member
@dgreenhouse
Thanks dgreenhouse. I am actually a novice. I know there is $_FILES['pic']['name'] in the code so am I to change it again? Why is the code as it is not inserting name into the database? It is uploading the pictures but it is not inserting the names. I changed $_POST or $_FILES[temp_file] to just $temp_file and got some charaters inserted but there are not proper names of the files. I changed tmp_name to simply 'name' and got the names inserted but then the picture then refused to load.
Jan 13 '10 #3
liberty1
3 New Member
UPDATE: Once again thank you. I finally changed tmp_name in $_FILES['pic']['tmp_name'] to just 'name' thus becoming $_FILES['pic']['name'] in my main code and changed $temp_file to $_FILES['pic']['tmp_name'] in the move to server part of the code. And that did it. The $_FILES[temp_file] in the process for submit into database (i.e., processinterview.php) part was also changed to just $temp_file. So now I am able to upload picture and insert the name in the database. Thank you for your help. I will work on the remainder parts as you suggested.
Jan 13 '10 #4
dgreenhouse
250 Recognized Expert Contributor
Glad you're on the right track...
Jan 13 '10 #5

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

Similar topics

7
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different...
3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
11
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store...
3
by: Surya | last post by:
Dear All, I have problem on inserting a record to database..Although it looked easy.. i have caught up with following issue .. please go ahead and help me to find solution I Need to insert...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
18
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
2
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.