I want to be able to offer someone the ability to upload a file and then to have the list refresh and available as a link.
I've been playing around with a couple of pieces of separate php code. I combined them into one file and everything seemed to work perfectly, but the link is off. It lists the link as http://www.domain.com/code.php/files/filename.jpg
Why is the .php filename showing up in the middle? Anyone?
Here's the code . . . I'm painfully new to .php
Code:<?php // set your folder // give write rights on that folder $uploaddir="files/"; $uploadfile =basename($_FILES['nimage1']['name']); $filename = basename($_FILES['nimage1']['name']); if (move_uploaded_file($_FILES['nimage1']['tmp_name'], "$uploaddir/$uploadfile")) { //that mean upload is completed with success; $msg = "success"; }else{ //that mean upload faild; $msg = "failed"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Upload</title> <style type="text/css"> <!-- p, h1, h2, h3, h4, td, blockquote, li { font-family: Verdana, Helvetica, sans-serif; color: #666666; font-size: 11px; line-height: 18px; text-align: left; margin: 0; padding: 0; } a:link, a:visited, a:hover { color:#0066CC; } .file{ padding-left: 1em; } .dir{ padding-left: 0; } --> </style> </head> <body style="font-family:Arial; font-size:10px;"> <form name="addnews" enctype="multipart/form-data" method="post" action="upload2.php"> <table border=0 cellspacing=1 cellpadding=4 align=center width=100% bgcolor="#000000"> <tr bgcolor="#FFFFFF"> <td valign="top" align="left"><input type="hidden" name="MAX_FILE_SIZE2" value="500000"/> <input name="nimage1" type="file" size="60" style="font-family:Arial; font-size:12px;"></td> </tr> <tr bgcolor="#FFFFFF"> <td valign="top" align="left"> <input type="submit" name="submit" value=" Submit " class="button"> </td> </tr> </table> </form> <hr /> <?php $dir="files/"; if ($dir_list = opendir($dir)) { while(($filename = readdir($dir_list)) !== false) { if($filename != "." && $filename != ".." && $filename != ".htaccess" && $filename != "index.htm") // check for '.' '..' '.htaccess' 'index.htm' { if(is_dir($dir.$filename)) $class="dir"; else $class="file"; ?> <li class="<?php echo $class; ?>"><a href="files/<?php echo $filename; ?>" target="_blank"><?php echo $filename;?></a></li> <?php } } closedir($dir_list); } ?> </body> </html>



Reply With Quote

Bookmarks