Jump to content

Problem about Upload/Delete/Rename file


mostafa_dadgar

Recommended Posts

hi

i write this code

I have some Problem

<HTML><HEAD><TITLE>Viewing Files in a Directory</TITLE></HEAD><BODY><TABLE BORDER=0 WIDTH="60%" CELLSPACING=2 CELLPADDING=2 ALIGN=CENTER><?phpif (@$Upload) { // Handle file uploads. 	print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Uploaded file name: $File_name</TD></TR>n"); 	print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Uploaded file size: $File_size</TD></TR>n"); 	if (copy ($File, "users/$File_name")) { 		print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $File_name, was successfully uploaded!</TD></TR>n"); 	} else { 		print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $File_name, could not be copied.</TD></TR>n"); 	} 	unlink ($File); 	print ("<TR><TD COLSPAN=4 ALIGN=CENTER> </TD></TR>n");}if (@$Delete) { // Handle file deletions. 	for ($i = 0; $i < count ($Delete); $i++) { 		if ( unlink ("users/$Delete[$i]") ) { 			print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $Delete[$i], was successfully deleted!</TD></TR>n"); 		} else { 			print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $Delete[$i], could not be deleted.</TD></TR>n"); 		} 	} 	print ("<TR><TD COLSPAN=4 ALIGN=CENTER> </TD></TR>n");}if (@$Rename) { // Handle file renaming. 	for ($n = 0; $n < count ($Rename); $n++) { 		$OldFilename = $Rename[$n]; 		$Old = "users/$OldFilename"; 		$New = "users/$NewName[$OldFilename]"; 		if ( rename ($Old, $New) ) { 			print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $Rename[$n], was successfully renamed!</TD></TR>n"); 		} else {			print ("<TR><TD COLSPAN=4 ALIGN=CENTER>Your file, $Rename[$n], could not be renamed.</TD></TR>n"); 		} 	} 	print ("<TR><TD COLSPAN=4 ALIGN=CENTER> </TD></TR>n");}// Start the form.print ("<FORM ACTION="files.php" METHOD=POST ENCTYPE="multipart/form-data">n");print ("<TR><TD><B>File Name</B></TD><TD><B>File Size</B></TD><TD><B>Delete</B></TD><TD><B>Rename</B> (Enter the New Name in the Box)</TD></TR>n");// Read the files from the directory.$Open = opendir ("users");while ($Files = readdir ($Open)) { 	$Filename = "users/" . $Files; 	if (is_file ($Filename)) { 		$Size = filesize ("users/$Files"); 		print ("<TR><TD>$Files</TD><TD>$Size</TD><TD><INPUT TYPE=CHECKBOX NAME="Delete[]" VALUE="$Files"></TD><TD><INPUT TYPE=CHECKBOX NAME="Rename[]" VALUE="$Files"><INPUT TYPE=TEXT NAME="NewName[$Files]"></TD></TR>n"); 	}}closedir ($Open);// Give the upload option.print ("<TR><TD COLSPAN=4 ALIGN=CENTER> </TD></TR>n");print ("<TR><TD COLSPAN=4 ALIGN=CENTER><INPUT TYPE=CHECKBOX NAME="Upload" VALUE="Yes">Upload a file to theserver:<INPUT TYPE=FILE NAME="File" SIZE=20></TD></TR>n");print ("<TR><TD COLSPAN=4 ALIGN=CENTER><INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"></FORM></TD></TR>n");?></TABLE></BODY></HTML>

when test this code in localhost, this code work correctly

but when Upload this code On my Host dont work.

http://gammarad.net/Test/PHPTest/files.php

please help me

Link to comment
Share on other sites

That code looks pretty old, it looks like you are relying on the register_globals option. Add this to the top of your PHP code:

ini_set('display_errors', 1);ini_set('scream.enabled', 1);error_reporting(E_ALL);
You should see several error messages about undefined variables. This is the feature you are relying on:http://php.net/manual/en/security.globals.phpYou're trying to use variables like $Upload and $Delete, but those variables are not defined. The register_globals setting would cause them to be defined, but you shouldn't use register_globals, you should define them yourself. When you submit that form all of the form data will be in $_POST, so you need to get the values from there. You can use print_r($_POST) if you want to see what it contains. There are some examples here about processing forms:http://www.w3schools.com/php/php_forms.aspThere's also a section in the manual about how to handle file uploads:http://php.net/manual/en/features.file-upload.php
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...