PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 31st, 2003, 11:59 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Uploading with PHP

I created a form. Very simple - it emails the responses from the form submission to an email that I have specified in the response.php file.

I also have a text box and button that is supposed to allow users to upload a file and send it with their form submission.

I wanted to know whether you guys could tell me how I could go about adding that function to my form? Your help would be extremely appreciated!

Thanks in advance guys
best regards,
kh44na

Reply With Quote
  #2  
Old April 1st, 2003, 07:11 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Take a look at the "insert images into database" posting your answer is probably there

Reply With Quote
  #3  
Old April 1st, 2003, 07:22 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
<?php
if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']))) die("Cannot upload files.");
?>


I used the above code to create an upload script....it works fine - when I select a file to upload - it works fine...and I am directed to my thank you page....

HOWEVER...if I chose NOT to upload a file - I get an ugly php error saying file not uploaded.....(which makes sense) - but I want the users to be able to CHOSE whether to upload a file or not....and when they decide NOT TO UPLOAD A FILE....I want it to process the form normally and not give me that ugly php error.

Reply With Quote
  #4  
Old April 1st, 2003, 07:37 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How about:

if($_Files['userfile']){

if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name'])))
die("Cannot upload files.");
}

Reply With Quote
  #5  
Old April 1st, 2003, 07:56 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
thanks for your quick reply - that idea does work - and when no file is selected or BROWSED, it DOES in fact successfully display my thank you page - but now when I DO upload a file (it doesn't copy into the UPLOAD directory)

Reply With Quote
  #6  
Old April 1st, 2003, 08:13 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Here's what i'd try.
//Open or create the file for writing

if($fp = fopen($filename, 'w')){
//Write to the file
if ($x = fwrite($fp, $img)){
unset($x);
}
else{
$stats .= 'An image requested for this page could not be saved <br>';
}
fclose($fp);
}

//This is part of a larger clase file.

Wrap this in the if test I suggesred earlier

Luck

Reply With Quote
  #7  
Old April 1st, 2003, 08:41 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
that' gives me a variable error - ?

Any ideas??

basically the only problem that i'm having is that I want users to upload a file to a directory....but when they DON"T browse for anything, I want the thank you page to show up as normal.

what code is required for that?

Reply With Quote
  #8  
Old April 1st, 2003, 10:06 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
I'm going to paste my reponse page - to show you:
---------------------------------------------------------------------------
<?php
$mailTo="ayyaz@dreamnation.ca";
$mailSubject="Blast Entertainment - Submit Article";

$mailBody=$mailBody."Full Name: " .$fullname. "\n";

$mailBody=$mailBody."Date of Report: " .$dateofreport."\n";

$mailBody=$mailBody."Time of Report: " .$report_time. "\n";

$mailBody=$mailBody."AM or PM: " .$amorpm. "\n";




$mailBody=$mailBody."Article Title: " .$articletitle. "\n";

$mailBody=$mailBody."Written by: " .$writtenby."\n";




$mailBody=$mailBody."Article: " .$articlepaste."\n";

$mailBody=$mailBody."Other Comments: " .$othercomments."\n";




mail($mailTo, $mailSubject, $mailBody, $mailHeaders);
?>

<?php
if(!$_FILES['userfile']['name']) die("Thank you");
if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']))) die("Cannot upload files.");
?>

<html>
<head>
<title> Response Page - Blast Entertainment </title>
<head>

<body bgcolor="#ffffff">
<font face="arial,helvetica,sans-serif" size="4" color="red"> <b> Article Submitted
Successfully! </b> </font>
<p><font size="2"" face="arial, helvetica, sans-serif">The article you submitted
has been sent.</font><font face="arial, helvetica, sans-serif" size=2"><p>



<a href=home.php"> Return to Main Page </a>
</font>


</body>
</html>
-------------------------------------------------------------------------------



Everything is fine - my thank you page is displayed if a file is uploaded. If a file isn't uploaded I receive a text phrase that says "Thank You" - as you will notice by looking at die("Thank you");

HOWEVER.....if a file isn't selected for upload.....how can I make my nice looking thank you page show up (as apposed to the Times New Roman text phrase that says "Thank You".

maybe that makes a bit more sense? - and one of you guys can help me out....lol

I REALLY APPRECIATE everything - thanks in advance.

Reply With Quote
  #9  
Old April 2nd, 2003, 11:05 AM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try it this way:-

//This tests wether the file has been uploaded or not.
//Wrap the copy portion inside the exists test or it will return an error
//Note the curly braces

if(!$_FILES['userfile']['name'])
{
//If the file has been uploaded copy it
if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name'])))
die("Cannot upload files.");
}
die("Thank you");
/*
If you don't get a file uploaded, try
echo "$_FILES_['userfile']['name'] <br>";
inside the same curly braces, and before the copy

*/

Reply With Quote
  #10  
Old April 2nd, 2003, 11:17 AM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
grrrr....

I don't have a clue why this doesn't seem to be working....

perhaps I'm not writing the code in correctly, or perhaps I'm not putting the code in the correct order...(I'm not a programmer at all - so you need to be really specific with me lol)....

I REALLY appreciate your help....but this script is being very stubborn with me.....

Reply With Quote
  #11  
Old April 2nd, 2003, 01:09 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post your code, including your form.

Post your error messages

If you swear to yourself a lot you are becoming a programmer.

Where are you located?

Reply With Quote
  #12  
Old April 2nd, 2003, 03:58 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
I thought you would be fed up by now - but you're more helpful than I could have imagined dude - let me show you:


MY HTML PAGE - OR FORM
---------------------------------------------------------------------------------
<html>
<head>
<title>Blast Entertainment: Online Reporting Application - Movie in Theatres</title>
</head>

<body>
<p><font color="#333333" size="5" face="Verdana, Arial, Helvetica, sans-serif">BLAST
ENTERTAINMENT</font></p>
<p><font color="#333333" size="5" face="Verdana, Arial, Helvetica, sans-serif">Submit
Article</font></p>
<p>&nbsp;</p>
<form action="article_response.php" method="post" enctype="multipart/form-data">
<table width="587" border="0" align="center">
<tr>
<td colspan="3"><font color="#006699" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>USER
INFORMATION:</strong></font></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="200"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Full Name:</font></strong></td>
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input name="fullname" type="text" id="fullname">
</font></td>
</tr>
<tr>
<td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Date of Submission:</font></strong></td>
<td width="205"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<br>
<strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="dateofreport" type="text" id="dateofreport">
</font></strong></font></td>
<td width="168"><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><br>
E.G.) </strong>March 02, 2003</font></td>
</tr>
<tr>
<td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Time:</font></strong></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input name="report_time" type="text" id="report_time" size="5" maxlength="4">
<select name="amorpm" id="amorpm">
<option value="am">AM</option>
<option value="pm">PM</option>
</select>
</font></td>
<td><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><br>
E.G.) </strong>5:45</font></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>
<br>
<br>
<table width="587" border="0" align="center">
<tr>
<td colspan="3"><font color="#006699" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>MOVIE
INFORMATION:</strong></font></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td width="198"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Article Title:</font></strong></td>
<td colspan="2"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input name="articletitle" type="text" id="articletitle">
</font></td>
</tr>
<tr>
<td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Written by:</font></strong></td>
<td width="379"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<br>
<strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="writtenby" type="text" id="writtenby">
</font></strong></font></td>

</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>
<br>
<br>
<table width="587" border="0" align="center">
<tr>
<td colspan="3"><font color="#006699" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>SUBMIT
ARTICLE:</strong></font></td>
</tr>
<tr>
<td colspan="3"><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Please
use the functions provided below to submit your article. You may paste
the entire article in the text area provided below, or upload a word document
if you have written your article using Microsoft Word.</font></td>
</tr>
<tr>
<td width="230"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Article:</font></strong></td>
<td colspan="2"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<textarea name="articlepaste" cols="50" rows="15" id="articlepaste"></textarea>
</font></strong></td>
</tr>
<tr>
<td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Browse for word document:</font></strong></td>
<td colspan="2"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <input type="file" name="userfile">
</font></strong></td>
</tr>
<tr>
<td><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
Any other comments:</font></strong></td>
<td colspan="2"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
<textarea name="othercomments" cols="40" rows="5" id="othercomments"></textarea>
</font></strong></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="109"><input type="submit" value="Submit Article"></td>
<td width="234"><input type="reset" name="Reset" value="Cancel"></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>
------------------------------------------------------------------------------------


MY RESPONSE PAGE - is provided above

Perhaps that will help.

I'm located in Toronto (Richmond Hill) - do you have icq?

Reply With Quote
  #13  
Old April 2nd, 2003, 04:48 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Your form looks fine.
Try printing out everything you can.
And send me any errors, or missing results.

I'm in Nova Scotia, and I'll set up icq later

Reply With Quote
  #14  
Old April 2nd, 2003, 05:19 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
There is no problem....
<?php
if(!$_FILES['userfile']['name']) die("Thank You");
if(!(copy($_FILES['userfile']['tmp_name'], "Upload/" . $_FILES['userfile']['name']))) die("Cannot upload files.");
?>

that is the php code I'm using in my response page currently.....When I select a file for upload and hit submit, I get my html THANK YOU PAGE (nice looking page - with different fonts, and colours - etc).

When I chose NOT to select a file for upload - I get an ugly times new roman text phrase that says Thank You - instead of that - if a user choses not to select something for upload - I want it to go and display my nice looking thank you page.....

Reply With Quote
  #15  
Old April 2nd, 2003, 06:22 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try This it worked on my machine

$imgname = $_FILES['userfile']['name'];

if($imgname){
if(!(copy($_FILES['userfile']['tmp_name'], ], "Upload/" . $imgname)))
{
die("Cannot upload files.");
}
else{
echo "File Copied<br>";
}
}
die("Thank You");

Reply With Quote
  #16  
Old April 2nd, 2003, 06:28 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16

Reply With Quote
  #17  
Old April 2nd, 2003, 08:12 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is the error I get now..

Parse error: parse error, unexpected ']' in /vhome/dreamnation.ca/htdocs/testing/blastentertainment/reportingsystem/article/article_response.php on line 36

Parse error are usually quite simple. In most cases the error will be on or before the line given in the error notice.

In this case, if this is the same error you get try matching [ and ] around line 36 to be sure you have the correct number.

The error could be something as simple as a missing comma or semi-colon.

I am downloading ICQ now, and will let you know when I am on.

Reply With Quote
  #18  
Old April 2nd, 2003, 08:18 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
my icq number is 109991795 - send me a message

Reply With Quote
  #19  
Old April 2nd, 2003, 08:19 PM
rickwright rickwright is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Nova Scotia
Posts: 27 rickwright User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
note the extra ], in the last code I sent

if(!(copy($_FILES['userfile']['tmp_name'], ], "Upload/"

Sorry about that!

Reply With Quote
  #20  
Old April 2nd, 2003, 09:10 PM
kh44na kh44na is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 37 kh44na User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
That's great - it works fine...but doesn't fix my initial problem...

I don't want to see Times New Roman text.....I want to see my HTML thank you page (in both instances - upload or no upload).

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Uploading with PHP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap