- Joined
- Jul 1, 2007
- Messages
- 367
- Reaction score
- 1
Okay, RaGEZONE.
I've started writing my own Image Board script, and I'm having trouble with the hardest part - the images.
For some reason, the browser outputs a message telling me the file is uploaded, but I check the directory and it is not there.
I've been working off of the File Upload Script from W3Schools, so I have no idea what is wrong with it.
Also, my directory for the uploaded file's CHMOD is 777, so that isn't a problem.
Edit
-
In my script, what I am trying to do, is upload the image with a different name, by the way.
Do you have any clue why I'm failing? If so, thanks.
/scripts/newthread.php:
I've started writing my own Image Board script, and I'm having trouble with the hardest part - the images.
For some reason, the browser outputs a message telling me the file is uploaded, but I check the directory and it is not there.
I've been working off of the File Upload Script from W3Schools, so I have no idea what is wrong with it.
Also, my directory for the uploaded file's CHMOD is 777, so that isn't a problem.
Edit
-
In my script, what I am trying to do, is upload the image with a different name, by the way.
Do you have any clue why I'm failing? If so, thanks.
/scripts/newthread.php:
PHP:
<?php
// New Thread Function
$con = mysql_connect('localhost', '*****', '*****') or die(mysql_error());
mysql_select_db('*****', $con) or die(mysql_error());
# OP's Details
$name = $_POST['name'];
$tripcode = $_POST['tripcode'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comment = $_POST['post-text'];
$date = date("F j, Y, g:i a");
#-> Filter Details
if ($name == "")
{
$name = "Anonymous";
}
if ($tripcode != "")
{
$tripcode = md5($tripcode . "#*(UWEJn");
}
# Begin Script:
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/png")
))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: Invalid File.";
}
else
{
$filename = $_FILES["file"]["name"];
$filesize = $_FILES["file"]["size"];
$filename_encrypted = rand(100000000000, 999999999999);
if (file_exists("/bimages/" . $filename_encrypted) == true)
{
echo "Error: File Error, please try again";
}
else
{
// Save thread
$SQL = "INSERT INTO `threads` (name, tripcode, email, subject, comment, date, image, encimage)
VALUES ('$name', '$tripcode', '$email', '$subject', '$comment', '$date', '$filename', '$filename_encrypted')";
mysql_query($SQL) or die(mysql_error());
// Save file
move_uploaded_file($_FILES["file"]["name"], "/bimages/" . $filename_encrypted . ".png");
echo "Thread created, file <i>" . $filename . "</i> uploaded!<br>
Now going to your new thread.";
}
}
}
else
{
echo "Error: Invalid file type.";
}
?>

