Jump to content

Upload files---Need Help


b_kitty

Recommended Posts

I have a script that allows file upload.

It seems like it works when i use it in my local webserver but when the scripts are transfered in a different web server, it does no long work.

I think this my be a path problem, maybe something wrong with my $archive_dir value!

 

Is there any rule on this value?????

 

Or maybe there is something wrong with the webserver itself?! :-\

 

I really Hope someone could Help..!! ::)

Link to comment
https://forums.phpfreaks.com/topic/37782-upload-files-need-help/
Share on other sites

are you copying the file to a directory?

What does your upload script look like?

 

 

function upload_copy_file() {
	if (is_uploaded_file($_FILES['file']['tmp_name'])) {
		$file 	= $_FILES['file']['name'];
		$path	= '/uploads/' . $file;
		if (copy($_FILES['file']['tmp_name'], $path)) { return 1; }
		else { return 2; }
	}
	else { return 3; }
}

yes, i am copping the files in a directoy on the web server.

My upload script is:

 

function upload_file() {

global $userfile, $userfile_name, $userfile_size,

$userfile_type, $archive_dir, $WINDIR;

if(isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile);

$filename = basename($userfile_name);

if($userfile_size <= 0) die ("$filename is empty.");

if(!@copy($userfile, "$archive_dir/$filename"))

die("Nuk mund të kopjojë $userfile_name tek $filename.");

//if(isset(!$WINDIR) && !@unlink($userfile))

//die ("Can't delete the file $userfile_name.");

echo "Imazhi $filename u upload-ua me sukses.<BR>";

echo  "<a href=mod_imazhe.php>Klioni ketu per te bere upload nje imazh tjeter</a>" ;}

No problem :)

 

I'm sure the problem is that you're not copying the file from the temp directory of the host. If you take a look at the upload_copy_file() function i posted here above, you can see how it takes the http post info and determines if the file has been uploaded. Also, in your upload form, do you have the: enctype="multipart/form-data" tag included? The file will not send to the server if it isn't present. If you want, i can take a look at your entire script and try to debug it for you (I'm avoiding doing my own work at the moment.. teehee).

Try using this as  your upload function:

function upload_file() {
// Check to see if the file has been uploaded to the server
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
	// get the file name from the form and replace spaces with underscore '_'
	$userfile		=		str_replace(' ', '_', $_FILES['userfile']['name']);

	// Set the save to directory
	$saveto		=		'../../Index/imazhe/';

	// Copy the file from the servers temp directory to your sites directory
	if (copy($_FILES['file']['tmp_name'], $saveto . $file)) { 
		// If successful -> echo upload message and exit function
		echo "Imazhi $filename u upload-ua me sukses.<BR>"; return; 
	}

	// If unable to copy send error message and exit the function
	else { 
		echo "Nuk mund të kopjojë $userfile_name tek $userfile.";  return;
	}
}// end if_uploaded_file();

// Send Error message if unable to upload file
else { echo "ERROR UPLOADING FILE"; return; }
}// end upload_file()

 

Sorry it took me so long to get back to you, I needed to eat :D

oops light error :-\

 

Try using this as  your upload function:

function upload_file() {
// Check to see if the file has been uploaded to the server
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
	// get the file name from the form and replace spaces with underscore '_'
	$file		=		str_replace(' ', '_', $_FILES['userfile']['name']);

	// Set the save to directory
	$saveto		=		'../../Index/imazhe/';

	// Copy the file from the servers temp directory to your sites directory
	if (copy($_FILES['file']['tmp_name'], $saveto . $file)) { 
		// If successful -> echo upload message and exit function
		echo "Imazhi $filename u upload-ua me sukses.<BR>"; return; 
	}

	// If unable to copy send error message and exit the function
	else { 
		echo "Nuk mund të kopjojë $userfile_name tek $file.";  return;
	}
}// end if_uploaded_file();

// Send Error message if unable to upload file
else { echo "ERROR UPLOADING FILE"; return; }
}// end upload_file()

 

Sorry it took me so long to get back to you, I needed to eat :D

It is a LINUX server.

 

I tried the script in XAMPP environment and it worked! But it doesn't where it should...in the LINUX server :(

Anyway, for security reasons, the hosting guys dont allow ftp for any user..only internal users, so i need the browser version of upload for the users to upload from anywhere!

Archived

This topic is now archived and is closed to further replies.

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