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 July 8th, 2002, 07:27 AM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
php probs

i've been working on some php scripts and to help me out i installed apache mysql and php4.2 on my windows based system. All works brill on my server but when i upload to my server i am having problems getting the thing to work.

It's basically a file upload script that puts the album and artist into a mysql database and the jpg files into a directory after renaming them. Well it does on my server but not on the unix host i want to use. I've changed all the mysql connection data and is correct. When i click on submit neither the database is undated with the new data and the file uploads don't upload to the given directory. I set the mysql database up using phpmyadmin and i can add data to the tables using this but my script just won't add the data.

Do i need to make any changes to the script in order for it to work on the unix host. Below is the script. You may find it abit long winded as it's my very first script but i was chuffed it worked on my server just hope someone can help me get it to work on my unix host. Thanks for your time and hope someone can help.

<html>
<head><title>Enter Cover Details</title><head>
<body>
<DIV align="center">

<form name="covers" method="post" action="<? $PHP_SELF ?>">
Artist: <input type="text" name="artist" size="27"></FONT></TD>
Album: <input type="text" name="album" size="27"><BR><BR>

<DIV align="center">
<TABLE BORDER=1 WIDTH="50%">

<TR bgcolor="#FFFFFF">
<TD align=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Front:
</FONT></B></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2">


<INPUT type="FILE" name="fnt" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#DDDDDD">
<TD align=center width="94">
<DIV align="left"><FONT face="Arial, Helvetica" size="2">
<B>&nbsp;&nbsp;Back:</B></FONT><FONT face="Arial, Helvetica" size="2" color="#000080">
</FONT></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2" color="#000080">
<INPUT type="FILE" name="bk" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD align=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Cd One:</FONT></B></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="c1" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#DDDDDD">
<TD align=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Cd Two:</FONT></B></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="c2" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD ALIGN=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Inside:
</FONT></B><FONT face="Arial, Helvetica" size="2"> </FONT></DIV>
</TD>
<TD ALIGN=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="ise" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#DDDDDD">
<TD align=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Inlay:
</FONT></B><FONT face="Arial, Helvetica" size="2"> </FONT></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="iny" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD ALIGN=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Extra One:
</FONT></B><FONT face="Arial, Helvetica" size="2"> </FONT></DIV>
</TD>
<TD ALIGN=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="ex1" size="38">
</FONT></TD>
</TR>
<TR bgcolor="#DDDDDD">
<TD align=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;Extra Two:
</FONT></B><FONT face="Arial, Helvetica" size="2"> </FONT></DIV>
</TD>
<TD align=center width="406"><FONT face="Arial, Helvetica" size="2">
<INPUT type="FILE" name="ex2" size="38">
</FONT></TD>
</TR>

<TR bgcolor="#FFFFFF">
<TD ALIGN=center width="94">
<DIV align="left"><B><FONT face="Arial, Helvetica" size="2"> &nbsp;&nbsp;
</FONT></B><FONT face="Arial, Helvetica" size="2"> </FONT></DIV>
</TD>
<TD ALIGN=center width="406"><FONT face="Arial, Helvetica" size="2">
<input type="submit" name="enter_data" value="Upload Covers">
</FONT></TD>
</TR>
</form>
</table>
</DIV>

</body>
</html>


<?

$database_name = "xxxx";


$dbh = mysql_connect("localhost","user","mypassword");


if (!mysql_select_db($database_name)) {
echo "Can't Select $database_name";
}


if ($enter_data) {
$front = "N";
$back = "N";
$cd1 = "N";
$cd2 = "N";
$inside = "N";
$inlay = "N";
$extra1 = "N";
$extra2 ="N";
if ($fnt != "") $front = "Y";
if ($bk != "") $back = "Y";
if ($c1 != "") $cd1 = "Y";
if ($c2 != "") $cd2 = "Y";
if ($ise != "") $inside = "Y";
if ($iny != "") $inlay = "Y";
if ($ex1 != "") $extra1 = "Y";
if ($ex2 != "") $extra2 = "Y";

$sql = "insert into covers (Artist, Album, front, back, cd1, cd2, inside, inlay, extra1, extra2)
values ('$artist', '$album', '$front', '$back', '$cd1', '$cd2', '$inside', '$inlay', '$extra1', '$extra2')";


$res = mysql_query($sql,$dbh);


if (!$res) {
echo mysql_errno().": ".mysql_error ()."";
return 0;
}

if ($fnt != "")copy ($fnt, "/usr/public_html/uploads/$artist-$album-front.jpg");
if ($bk != "") copy ($bk, "/usr/public_html/uploads/$artist-$album-back.jpg");
if ($c1 != "") copy ($c1, "/usr/public_html/uploads/$artist-$album-cd1.jpg");
if ($c2 != "") copy ($c2, "/usr/public_html/uploads/$artist-$album-cd2.jpg");
if ($ise != "") copy ($ise, "/usr/public_html/uploads/$artist-$album-inside.jpg");
if ($iny != "") copy ($iny, "/usr/public_html/uploads/$artist-$album-inlay.jpg");
if ($ex1 != "") copy ($ex1, "/usr/public_html/uploads/$artist-$album-extra1.jpg");
if ($ex2 != "") copy ($ex2, "/usr/public_html/uploads/$artist-$album-extra2.jpg");
printf("<p>Record successfully added. Feel free to enter more covers.</p>");
echo "<BR><a href=\"fwbtest.html\">OR RETURN TO MAIN PAGE</a><br>";

}

?>

Reply With Quote
  #2  
Old July 8th, 2002, 07:41 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Adrian,

What type of error messages, if any, do you receive?

What version of PHP are you running on your system? Also what version is running on your host's server? To find out, create a script and insert: "phpinfo();" as the only line... and run the script. it will display all the info about the PHP configuration on your host's machine.

By looking at your code, it may be that the version of PHP on the server has "register_globals" set to "off".

Rather than using:
PHP Code:
if ($enter_data) {
$front "N";
$back "N";
$cd1 "N";.... 


Try using:
PHP Code:
if ($_POST['enter_data']){
$front "N";... 


You should try to start using the superglobal arrays ($_POST[], $_GET[], etc...). To find out more, check out the PHP manual.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Last edited by Lindset : July 8th, 2002 at 08:06 AM.

Reply With Quote
  #3  
Old July 8th, 2002, 08:31 AM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your help frankie, register_globals is set to off with my host.

info is now going into my database but the files aren't getting uploaded. I've looked at the link you gave and to be honest at this stage in my learning it went straight over my head. I'm therfore once again asking for your help sorting the file upload problem out. i'm guessing it's me at fault. I knew that my script was probably not written in 100% correct manner but once i can get it running then i can use it as a base to learn more and get better understanding of writing scripts correctly.

Again thanks for your help it really is appreciated.

Reply With Quote
  #4  
Old July 8th, 2002, 09:18 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Adrian,

Looking through your code again, I noticed that you're making a lot of references to the variables from the HTML form (ie: fnt, artist, album, etc...).

Because "register_globals" is set to off on your host, what you need to do before using the copy() function is assign the values of the $_POST[] arrays to the variable names (in your php code).

ex:

$artist = $_POST['artist'];
$alubm = $_POST['album']'
...etc...

Assign EVERY incoming variable from the html form using the superglobals, and try the copy function again. It may just work.

Do you get any error messages when trying it now?

Reply With Quote
  #5  
Old July 8th, 2002, 10:09 AM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks once again frankie, i seem to be getting there. before i made the last changes you said, i got no error messages at all, the covers just didn't upload. Now i am getting the following error message

Warning: Unable to open 'C:\\My Documents\\My Covers\\fred-flint-front.jpg' for reading: No such file or directory in /usr/home/mysite_com/public_html/uploadform.php on line 159

Record successfully added. Feel free to enter more covers.


Now i'm assuming this is down to absolute path being wrong so i contacted my host for it and changed it to the following

if ($fnt != "")copy ($fnt, "/usr/home/mysite_com/public_html/uploads/$artist-$album-front.jpg");

I created a folder called uploads in my public_html folder and set chmod to give correct access rights

Thanks again for all your help you are giving me (i'd e-mail you a bottle of scotch if i could).

Reply With Quote
  #6  
Old July 8th, 2002, 10:12 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Have you got the entire script to work now, or are you still encountering some errors?

If there are still problems, post them here, and we will try to assist as much as we can!

Reply With Quote
  #7  
Old July 8th, 2002, 10:19 AM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The mysql database info is going in fine. the only prob i have now is with the file upload path. according to my host the path i have in my script is correct so i have no idea why the files won't upload to the path i have entered into my script just keep getting the error mentioned in last post.

Reply With Quote
  #8  
Old July 8th, 2002, 10:36 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Okay... Looking over the error msg again, it has to do with the path being provided for the file you're trying to upload:

Warning: Unable to open 'C:\\My Documents\\My Covers\\fred-flint-front.jpg' for reading: No such file or directory

If you notice, there's a double \\, so you'll need to strip the extra slash so that it appears: 'C:\My Doc...\My Cov...\filename.jpg'

You need to use the "stripslashes()" function to remove the additional "\"... Before your copy() statements, strip the slashes from every variable you're using:

PHP Code:
 $fnt stripslashes($fnt);   // c:\\\\filename.jpg becomes c:\\filename.jpg
etc...etc... 


Let me know how it goes!

Reply With Quote
  #9  
Old July 8th, 2002, 10:58 AM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again frankie. Used stripslashes but now get the same error but with single slashes

Warning: Unable to open 'C:\My Documents\My Covers\fred-flint-front.jpg' for reading: No such file or directory in /usr/home/mysite_com/public_html/uploadform.php on line 160


Sorry to be a pain, i really do appreciate your help.

Reply With Quote
  #10  
Old July 8th, 2002, 11:19 AM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Okay, I just took a look in the PHP manual.. Instead of doing:

$fnt = $_POST['fnt'];

Try:

$fnt = $_FILES['fnt']['name']; ('name' is the file that resides on the user's computer.
$bk = $_FILES['bk']['name'];
...etc...

Then try your copy function. If you need some more info, check out the page on the PHP Manual...

Let me know if this works for you!

Reply With Quote
  #11  
Old July 8th, 2002, 12:24 PM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
now i've done that i get no error messages but the file still does not upload.

Reply With Quote
  #12  
Old July 8th, 2002, 03:10 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Adrian,

The error message stated there was a problem on line 160 of the script. What's on line 160? That may help determine the cause. Unfortunately there aren't line #'s on the script you posted, so if you could print out line 160, it may help.

Reading through the PHP manual again, i noticed that your <form> tag doesn't have: enctype="multipart/form-data"...

Try changing the form tag to this:

<form name="covers" enctype="multipart/form-data" method="post" action="<? $PHP_SELF ?>">

It's also recommended to add a hidden field to set the maximum filesize. ex: <input type="hidden" name="MAX_FILE_SIZE" value="1024">

You can change the value to whatever you like (expressed in bytes).

Try that, and let me know! It's bugging me as much as it is you now!

Also, do you have a link to the form page?

Last edited by FrankieShakes : July 8th, 2002 at 03:15 PM.

Reply With Quote
  #13  
Old July 8th, 2002, 03:52 PM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks again for your help frankie,

The enctype="multipart/form-data" and type="hidden" name="MAX_FILE_SIZE" value="
i did after reading the link to the manual you gave me. i have also tried every way i can but still no look. even tried move_uploaded_file but still no joy. line 160 is the first line of the upload which is presently set to

if ($fnt != "") move_uploaded_file($_FILES['$fnt']['tmp_name'], "/usr/home/mysite_com/public_html/uploads/$artist-$album-front.jpg");
which i tried after reading the manual.

i'm going to pm you a link to the script and if it helps i can e-mail it to you aswell.

Once again thanks for your help, it's giving me a headache now. when i had it working on my own windows based server i thought i'd cracked it.

Reply With Quote
  #14  
Old July 8th, 2002, 05:55 PM
adrian adrian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 20 adrian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i've finally sorted it after trying every possible code permitation. Thanks frankie i couldn't have done it without your help. my host was wrong also about what i needed to enter for the absolute path. just to let you know, the lines i had to change were changed to

$fnt = $_FILES['fnt']['name'];

and

if ($fnt != "") copy($_FILES['fnt']['tmp_name'], "/usr/home/mysite_com/public_html/uploads/$artist-$album-front.jpg");

thanks again frankie. I just need to sort the script to just allow .jpg files now but that should be abit easier

Reply With Quote
  #15  
Old July 8th, 2002, 06:10 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Adrian,

No problem... I'm glad it was finally sorted out... I didn't understand why it wasn't working... Weird how you still needed to put the "$_FILES[...][...]" within the copy() function. Why it didn't work with the variable is baffling!

I'm glad you got it working!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > php probs


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