Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I am a little new to writing PHP, but stumbled my way to this point. I got a script that is supposed to add the file name to my database, and then upload the file to a specific directory. It adds it to the database fine, but does not show up in the directory it is supposed to, but says it complete sucessfully.
Any help would be appreciated. THANKS!!!
Here is the code: (Some of it - my path is correct, but I changed it in the example.)
<?
if ($action == "Load")
{
$folder = "/hsphere/local/home/user/website/images/reviews/";
@copy("$filep" , "$folder/$filep_name");
echo "
<p align=center>File $filep_name loaded...";
$result = mysql_connect("$host", "$user", "$pass") or die ("Could not save image nameError: " . mysql_error());
@mysql_select_db("$db") or die("Could not select database");
@mysql_query("INSERT into reviews (Picture) VALUES('$filep_name')");
if($result) { echo "Image name saved into database"; }
}?>
<html>
<body>
<head>
<title></title>
</head>
<form action=reviewupload.php method=post enctype="multipart/form-data">
<table border="0" cellspacing="0" align=center cellpadding="3" bordercolor="#cccccc">
<tr>
<td>File:</td>
<td><input type="file" name="filep" size=45></td>
</tr>
<tr>
<td colspan=2><p align=center>
<input type=submit name=action value="Load">
</td>
</tr>
</table>
</form></body>
</html>~Rich

First, remove all the @ characters from your commands...You shouldn't have those in there when you're developing a script, because they may be suppressing warnings and notices that will be useful in debugging.
Second, I don't see any reference here to the uploaded file...Maybe that's $file_p but I'm not sure. Check out the PHP manual article on Handling file uploads to learn how to do this bit properly.
Good luck,
-SN

I took out the @ symbols, but it still does not give any errors. From what I understood the $filep was the file path, but when I double checked and had it output the $filep to the screen it came out to /tmp/random characters
$filep_name is the actual filename of the file.
Something's wrong, but I'm still trying to figure out what.
I even went as far as to take the database part out, and even tried a script in an example like this one: http://www.htmlgoodies.com/beyond/php/article.php/3472551Uploading into the same directory as the php file still does not work. I am wondering if I have to set some sort of special permissions? Or if uploading could be disabled on my server?
I'm clueless.~Rich

OK, I just went ahead and modified the script for you. Give this a go.
-SN
<?
if ($_POST["action"] == "Load")
{
$folder = "/hsphere/local/home/user/website/images/reviews/";
move_uploaded_file($_FILES["filep"]["tmp_name"] , "$folder".$_FILES["filep"]["name"]);
echo "
<p align=center>File ".$_FILES["filep"]["name"]."loaded...";$result = mysql_connect("$host", "$user", "$pass") or die ("Could not save image name
Error: " . mysql_error());
mysql_select_db("$db") or die("Could not select database");
mysql_query("INSERT into reviews (Picture) VALUES('".$_FILES['filep']['name']."')");
if($result) { echo "Image name saved into database"; }
}
?>
<html>
<body>
<head>
<title></title>
</head><form action=reviewupload.php method=post enctype="multipart/form-data">
<table border="0" cellspacing="0" align=center cellpadding="3" bordercolor="#cccccc">
<tr>
<td>File:</td>
<td><input type="file" name="filep" size=45></td>
</tr>
<tr>
<td colspan=2><p align=center>
<input type=submit name=action value="Load">
</td>
</tr>
</table>
</form></body>
</html>

Woohoo! You got it! I did have to change the permissions on that directory, but I can't believe it's done! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you!!!!!!!!!!!!!!!!
~Rich

![]() |
banner image ?
|
Google Search Selection
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |