Jump to content

Recommended Posts

Posted

I'd like to see a working example if anyone has one

 

 

<html>

<head>

<title>doesn't work</title>

</head>

<?php

$file_dir = "/upload";

$file_url =

"http://www.mywebsite.com/public_html";

print "path: $fupload<br>\n";

print "name: $fupload_name<br>\n";

print "size: $fupload_size bytes<br>\n";

print "type: $fupload_type<p>\n\n";

 

copy ( $fupload, "$file_dir/$fupload_name") ;

 

print "<input value=\"$file_url/$fupload_name\"><p>\n\n";

 

?>

<body>

<form enctype="multipart/form-data" action="<?php print $PHP_SELF?>"

method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="51200">

<input type="file" name="fupload"><br>

<input type="submit" value="Send file!">

</form>

</body>

</html>

Posted

Here is my uploader that works for image files:

 

><?php

if (is_uploaded_file($_FILES['userpic']['tmp_name'])) {
   if ((substr($_FILES['userpic']['name'], -4) == '.jpg') || (substr($_FILES['userpic']['name'], -4) == '.gif') || (substr($_FILES['userpic']['name'], -4) == '.png'))  {
      
   if ($_FILES['userpic']['size'] > 300000) {
      exit("Picture is too large! Try compressing more!");
      }
   if (strlen($_FILES['userpic']['type']) > 26) {
      exit("Please rename the picture to something with a shorter name and try again!");
      }
   $filename = $_FILES['userpic']['name'];
   if (file_exists($_FILES['userpic']['name'])) {
      exit("This file already exists, please rename it!");
   }
      copy($_FILES['userpic']['tmp_name'], "/home/sector-/public_html/pics/".$_FILES['userpic']['name']);
      echo "File has been uploaded to S19's server.  Here are your details:<p>";
      echo "The URL to your picture is:<b> <a href=\"http://pics.sector-19.com/".$_FILES['userpic']['name']."\">http://pics.sector-19.com/".$filename."</a></b><br>";
      echo "The code to put this on the forums is:<b> [img=http://pics.sector-19.com/".$_FILES['userpic']['name']."]</b>";
}
else { exit("This is not a valid image file"); }
} else {
  echo "Possible file upload attack. Filename: " . $_FILES['userpic']['name'];
}

?>

Posted

Thanks for the help. I got it working using your example.

 

My other problem was setting write permission to the folder.

 

><?php

if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
$error = "You did not select a file to upload";
unlink($_FILES['file']['tmp_name']);

}
else
{
if( copy($_FILES['file']['tmp_name'],"upload/".$_FILES
['file']['name']) )
{
 print "copied";
}
else
{
 print "failed";
}
}	

?>
<html>
<head></head>
<body>
<form action="load.php" method="post"
enctype="multipart/form-data">
<?=$error?>
<br><br>
Choose a file to upload:<br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

  • 3 weeks later...
Posted
I don't think apache has the permissions to CHMOD on TCH.

Apache can't do the CHMOD but you can use FileManger under Cpanel to change your permissions for your directory so you can upload stuff there.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...