Help with uploading files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tuqire
Forum Newbie
Posts: 2
Joined: Tue Feb 03, 2009 7:58 pm

Help with uploading files

Post by tuqire »

Hi,

Im trying to upload images to a server but i cant get the php code to work. I have pretty much copied the code word for word from a tutorial - can any of you tel me why this is?

---------------------------------------------------------------------------------------------------
<?php
if (getimagesize($_FILES['file']['tmp_name']) && $_FILES['file']['error'] == UPLOAD_ERR_OK)
{
$currentdir=getcwd();
move_uploaded_file($_FILES['file']['tmp_name'],
$currentdir . $_FILES['file']['name']);
echo ("<h1>Well Done</h1>");
}

echo ("<form action='{$_SERVER['PHP_SELF']}' method='post' enctype='multipart/form-data'>

<label for='file'>Image:</label>
<input type='file' name='file' id='file' class = 'contactfield'/>

<input type='submit' class = 'submit' value='Create This Entry!' />
</form>
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with uploading files

Post by requinix »

You have a (" with the echo that starts the form but no ") to end it.
tuqire
Forum Newbie
Posts: 2
Joined: Tue Feb 03, 2009 7:58 pm

Re: Help with uploading files

Post by tuqire »

thanks for the quick response!

Seems i omitted the end of the echo from my copy and paste.

To elaborate on the issue the page loads fine - you can attempt to upload the file and then the message 'Well done' gets printed on screen when you submit the form but the actual file hasn't been uploaded. What possibly can be the issue have been through countless tutorials.
jh_1981
Forum Newbie
Posts: 22
Joined: Fri Jan 30, 2009 6:21 pm

Re: Help with uploading files

Post by jh_1981 »

$FileName=$UploadPath."upload/info_information/".$picture;
$file = $_FILES['file']['tmp_name'];
if(copy($file,$FileName))
{
unlink($file);
}
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Help with uploading files

Post by Benjamin »

Please use [ code = php ] tags guys.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with uploading files

Post by requinix »

$currentdir needs to be writable by everyone. In 'Nix that means it needs permissions 0777.

Go into your php.ini file, find the error_reporting setting, and change it to E_ALL. Then find display_errors and turn that "on". Restart your server.
This way you'll see any error messages PHP gives.
Post Reply