Results 1 to 3 of 3

Thread: Upload and list files

  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Upload and list files

    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>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    It... Weird, it doesn't for me... Try changing:
    Code:
    <li class="<?php echo $class; ?>"><a
    href="files/<?php echo $filename; ?>" target="_blank"><?php echo $filename;?></a></li>
    To:
    Code:
    <li class="<?php echo $class; ?>"><a
    href="/files/<?php echo $filename; ?>" target="_blank"><?php echo $filename;?></a></li>
    And if that isn't doing it, then this:
    Code:
    <li class="<?php echo $class; ?>"><a
    href="../files/<?php echo $filename; ?>" target="_blank"><?php echo $filename;?></a></li>
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    lrickyutah (03-04-2009)

  4. #3
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Thanks.

    All of a sudden, it works fine now. I'm wondering if I didn't clear my cache. duh.

    thanks for your help!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •