Jump to content

Recommended Posts

hey i'm kinda new to php, but i'm okay with html, css and some javascript/actionscript.

 

anyway i'm currently making my first proper website and need some help. one of the main functions of this website is that the user must be able to upload their own files (that bit i'm okay with), but i was wondering how if at all possible i would go about showing people in a nice pretty list the content that they have uploaded. Preferably also with options to delete/view selected uploaded content.

 

any help is greatly appreciated  ;D

<table align="center" cellpadding="5" cellspacing="5" border="0">
<tr>
    	<td align="center" class="gTxt"><b>Image Name</b></td>
        <td align="center" class="gTxt"><b>Image Size</b></td>
</tr>
    
<?php

$dir = 'uploads';
$files = scandir($dir);

foreach ($files as $image) {
if (substr($image, 0, 1) != '.') {
	$image_size = getimagesize("$dir/$image");
	$file_size = round ( (filesize("$dir/$image")) / 1024) . "kb";


	echo "<tr>
		<td>$image</a></td>
		<td>$file_size</td>
		</tr>";

	}
}
echo '</table>';
?>

 

This code creates a table in HTML, and then populates it with uploaded files in a upload directory. It displays the name and the size of the file. (This code is modified from my original script and I haven't tested it but it should work fine.)

PS. Sorry its not commented, you should be able to understand it easy enough:

 

$dir variable is the directory = uploads

$files variable is an array, the scandir() function scans all files in the directory ($dir)

 

It then does a foreach loop, which is basically saying transfer one variable from the array into $image until there are no files left, it then cuts the string of $image, gets the size and locates it and then puts it in a table.

I think it is right. Sorry for bad grammer.

 

thanks alot man :)

 

would this still work if i put the files in a drop down box so you could select one rather than a html table. and then two buttons afterwards one to delete the selected file from the directory and another to load it in a new window?

 

thanks for the help  :-*

Okay this is what i got by modifying the script to delete a selected file from the files displayed.

 

Showedit.php:

 

<?php

session_start()

?><center>

<form name="videoform" method="post" action="deletefile.php">

<select name="selectupload" id="selectupload" size="10">

   

<?php

 

$dir = 'Games/'. $_SESSION['nameuser'];

$files = scandir($dir);

 

foreach ($files as $image) {

if (substr($image, 0, 1) != '.') {

$image_size = getimagesize("$dir/$image");

$file_size = round ( (filesize("$dir/$image")) / 1024) . "kb";

 

 

echo " <option value=$image> File: $image      Size: $file_size      </option>";

 

}

}

echo '</select>';

?>

 

<BR><hr width="30">

<input type="submit" name="submit" value="Delete File"><BR><hr width="30"><br></center>

 

 

Deletefile.php:

 

<?php

session_start()

?>

<?php

$file=$_POST['selectupload'];

unlink ('Games/'. $_SESSION['nameuser'] . '/' . $file);

echo 'file deleted: ' . $file;

?>

 

 

 

I mite combine the two files later so they can be deleted faster.

 

Can any of you spot any immediate weaknesses in the script?

thanks :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.