|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
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"> 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> 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"> 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"> 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"> 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"> 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"> 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"> 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"> </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>"; } ?> |
|
#2
|
|||
|
|||
|
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:
Try using: PHP Code:
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
|||
|
|||
|
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). |
|
#6
|
|||
|
|||
|
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! |
|
#7
|
|||
|
|||
|
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.
|
|
#8
|
|||
|
|||
|
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:
Let me know how it goes! |
|
#9
|
|||
|
|||
|
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. |
|
#10
|
|||
|
|||
|
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! |
|
#11
|
|||
|
|||
|
now i've done that i get no error messages but the file still does not upload.
|
|
#12
|
|||
|
|||
|
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. |
|
#13
|
|||
|
|||
|
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. |
|
#14
|
|||
|
|||
|
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 |
|
#15
|
|
|
|