Jump to content

Form Upload Issue [php]


Fighters

Recommended Posts

What I've done is allow visitors to upload pictures of themselves along with a short description of who they are using HTML Forms. The form is then sent to me via email, and I upload it to the website. Now I'm not 100% sure, but I believe that the image that's uploaded must first go through a server side, because it's moved to a folder called "tmp." Therefore, I have a PHP script that moves it to my destination folder, and then renames the file to its original file name.

 

The issue is, when I receive the emails sent via form, the file's name is still "tmp/2140712.jpg" instead of it's original file name. But because it has already been moved, the file that was once "tmp/2140712.jpg" is now "thisisme.jpg." This was okay for a while, but I've been starting to receive multiple uploads at once, and I can no longer decipher which picture is which.

Link to comment
https://forums.phpfreaks.com/topic/117406-form-upload-issue-php/
Share on other sites

Here ya go!

 

<?php

$body = "Habbo Name: $name \n

Real Name: $realname \n

Email Address: $email \n

Age: $age \n

About Me: $aboutme \n

Picture: $uploadedfile \n

";

$name = $_POST['name'];

$realname = $_POST['realname'];

$email = $_POST['email'];

$age = $_POST['age'];

$aboutme = $_POST['aboutme'];

$uploadedfile = $_POST['uploadedfile'];

$body .= "IP address : ";

$body .= $_SERVER['REMOTE_ADDR'];

 

$from = "From: $email\r\n";

 

$target_path = "uploads/";

 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    echo "The file ".  basename( $_FILES['uploadedfile']['name']).

    " has been uploaded";

} else{

    echo "There was an error uploading the file, please try again!";

}

 

 

mail( "[email protected]", "Pixelbook Entry", $body, $from );

echo "<center><br /><br /><img src='../habbofigs/frontws.png' alt=' '></img><br />Thank you for signing up for Pixelbook!<br>Click <a href='signup.htm'>here</a> to go back.</a>";

 

?>

 

try this code:

 

<?php
//Get some variables
$name = $_POST['name'];
$realname = $_POST['realname'];
$email = $_POST['email'];
$age = $_POST['age'];
$aboutme = $_POST['aboutme'];
$uploadedfile = $_POST['uploadedfile'];

//Move File
$target_path = "uploads/" . $_FILES['uploadedfile']['name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file " . $_FILES['uploadedfile']['name'] . " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

//Build Email
$from = "From: $email\r\n";
$body = "Habbo Name: $name \n
Real Name: $realname \n
Email Address: $email \n
Age: $age \n
About Me: $aboutme \n
Picture: $target_path \n
IP address : {$_SERVER['REMOTE_ADDR']}";
mail( "[email protected]", "Pixelbook Entry", $body, $from );
echo "<center>

<img src='../habbofigs/frontws.png' alt=' '></img>
Thank you for signing up for Pixelbook!
Click <a href='signup.htm'>here[/url] to go back.[/url]";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.