Jump to content

Uploading files on Windows Environment


negvillamizar

Recommended Posts

Hi everyone.

 

I am having a bit of a problem, and I was wondering if some one can help me. I am running PHP, Apache and MySQL on an XP Professional PC, and I am trying to write some code to be able to upload pictures to my site. I have not be able to set the permissions to get the files moved from the temp upload folder to the location I want to put them.

 

Also, something odd is happening, If I do not specified a location to move the files, then it uses the root folder and move the files there, the wired thing is, that when I run the script the first time, it does not move the file and yet shows not errors or warnnings, but if I run it again, then it does move the file.

 

Does anyone have any ideas or guide lines ? I would really appreciate it.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/37808-uploading-files-on-windows-environment/
Share on other sites

Your file upload function should look something like this.

 

function upload_file() {

// Check to see if the file has been uploaded to the server
if (is_uploaded_file($_FILES['file']['tmp_name'])) {

	// get the file name from the form and replace spaces with underscore '_'
	$file = str_replace(' ', '_', $_FILES['file']['name']);

	// Set the save to directory
	$saveto = '/your_upload_dir/';

	// change the dir properties
	// Everything for owner, read and execute for others
	chmod($saveto, 0755);

	// Copy the file from the servers temp directory to your sites directory
	// If successful -> echo upload message and exit function
	if (copy($_FILES['file']['tmp_name'], $saveto . $file)) { return "Successfully Uploaded $file"; }

	// If unable to copy send error message and exit the function
	else { return "Unable to copy file to: '$saveto'";  }

}// end if_uploaded_file();

// Send Error message if unable to upload file
else { return "Unable to upload file: '$file'"; }

}// end upload_file()

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.