Anyone Have Upload Code That Works On Tch?

liunx

Guest
I'd like to see a working example if anyone has one<br /><br /><br /> <html><br /> <head><br /> <title>doesn't work</title><br /> </head><br /> <?php<br /> $file_dir = "/upload";<br /> $file_url =<br />"http://www.mywebsite.com/public_html";<br /> print "path: $fupload<br>\n";<br /> print "name: $fupload_name<br>\n";<br /> print "size: $fupload_size bytes<br>\n";<br /> print "type: $fupload_type<p>\n\n";<br /><br /> copy ( $fupload, "$file_dir/$fupload_name") ;<br /><br /> print "<input value=\"$file_url/$fupload_name\"><p>\n\n";<br /> <br /> ?><br /> <body><br /> <form enctype="multipart/form-data" action="<?php print $PHP_SELF?>"<br />method="POST"><br /> <input type="hidden" name="MAX_FILE_SIZE" value="51200"><br /> <input type="file" name="fupload"><br><br /><input type="submit" value="Send file!"><br /> </form><br /> </body><br /> </html><!--content-->
Here is my uploader that works for image files:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />if (is_uploaded_file($_FILES['userpic']['tmp_name'])) {<br />    if ((substr($_FILES['userpic']['name'], -4) == '.jpg') || (substr($_FILES['userpic']['name'], -4) == '.gif') || (substr($_FILES['userpic']['name'], -4) == '.png'))  {<br />       <br />    if ($_FILES['userpic']['size'] > 300000) {<br />       exit("Picture is too large! Try compressing more!");<br />       }<br />    if (strlen($_FILES['userpic']['type']) > 26) {<br />       exit("Please rename the picture to something with a shorter name and try again!");<br />       }<br />    $filename = $_FILES['userpic']['name'];<br />    if (file_exists($_FILES['userpic']['name'])) {<br />       exit("This file already exists, please rename it!");<br />    }<br />       copy($_FILES['userpic']['tmp_name'], "/home/sector-/public_html/pics/".$_FILES['userpic']['name']);<br />       echo "File has been uploaded to S19's server.  Here are your details:<p>";<br />       echo "The URL to your picture is:<b> <a href=http://www.totalchoicehosting.com/forums/lofiversion/index.php/\"http://pics.sector-19.com/".$_FILES['userpic']['name']."\">http://pics.sector-19.com/".$filename."</a></b><br>";<br />       echo "The code to put this on the forums is:<b>
".$_FILES['userpic']['name']."
</b>";<br />    }<br />    else { exit("This is not a valid image file"); }<br />} else {<br />   echo "Possible file upload attack. Filename: " . $_FILES['userpic']['name'];<br />}<br /><br />?><!--c2--></div><!--ec2--><!--content-->
Thanks for the help. I got it working using your example.<br /><br />My other problem was setting write permission to the folder.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />if (!is_uploaded_file($_FILES['file']['tmp_name'])) {<br />$error = "You did not select a file to upload";<br />unlink($_FILES['file']['tmp_name']);<br /><br />}<br />else<br />{<br />    if( copy($_FILES['file']['tmp_name'],"upload/".$_FILES<br />    ['file']['name']) )<br />    {<br />  print "copied";<br />    }<br />    else<br />    {<br />  print "failed";<br />    }<br />}    <br /><br />?><br /><html><br /><head></head><br /><body><br /><form action="load.php" method="post"<br />enctype="multipart/form-data"><br /><?=$error?><br /><br><br><br />Choose a file to upload:<br><br /><input type="file" name="file"><br><br /><input type="submit" name="submit" value="submit"><br /></form><br /></body><br /></html><!--c2--></div><!--ec2--><!--content-->
I don't think apache has the permissions to CHMOD on TCH.<!--content-->
<!--QuoteBegin-raDeon+Aug 6 2003, 03:09 PM--><div class='quotetop'>QUOTE(raDeon @ Aug 6 2003, 03:09 PM)</div><div class='quotemain'><!--QuoteEBegin-->I don't think apache has the permissions to CHMOD on TCH.<!--QuoteEnd--></div><!--QuoteEEnd--><br /> 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.<!--content-->
 
Top