Page 1 of 1

Upload Error

Posted: Mon Jul 19, 2010 8:51 pm
by Terukio
Okay so I'm using some PHP to create an upload script and I got this following error:

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpLZUTH4' to 'http://www.sition.net/upload/resources5558.s2z' in /home2/zack/public_html/includes/do_upload.php on line 29

Here is the code I used.

Code: Select all

<?php

$target = "http://www.sition.net/upload/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

if (!($uploaded_type=="s2z")) {

echo "You may only upload s2z or honmod files.<br>";

$ok=0;

}elseif (!($uploaded_type=="honmod")) {

echo "You may only upload s2z or honmod files.<br>";

$ok=0;

}

if ($ok==0) {

echo "Sorry your file was not uploaded";

}

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){

echo "The file " . basename( $_FILES['uploadedfile']['name']). "has been uploaded";

}else{

echo "Sorry, there was a problem uploading your file."; 

}
 
?> 
And here is the HTML form:

Code: Select all

<form enctype="multipart/form-data" action="http://www.sition.net/includes/do_upload.php" method="POST">Please Choose a file: <input name="uploaded" type="file"/><br/><input type="submit" value="Upload"/></form>

Re: Upload Error

Posted: Mon Jul 19, 2010 9:38 pm
by buckit
you need to use the actual path as the target

example:
/websites/mysite.com/files/thisismyfile.pdf

then access the file via http://mysite.com/files/thisismyfile.pdf




example path on a windows machine would be:
c:\websites\mysite.com\files/thisismyfile.pdf

Re: Upload Error

Posted: Mon Jul 19, 2010 10:44 pm
by Terukio
Okay thanks I got it able to upload, however I'm trying to restrict what type of files can be uploaded. (I want just .s2z files and .honmod files to be able to be uploaded.) What should I use to restrict something like that because I tried this:

Code: Select all

if ($uploaded_type =="text/x-generic") {
echo "Blah Blah Blah<br>";
$ok=0;
}
Which did not work. What do you suggest?

Code: Select all

<?php

$target = "/*/*/public_html/upload/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

if ($ok==0) {

echo "Sorry your file was not uploaded";

}else{

if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)){

echo "The file <b>".basename( $_FILES['uploaded']['name'])."</b> has been uploaded";

}else{

echo "Sorry, there was a problem uploading your file."; 

}
}
 
?>
 

Re: Upload Error

Posted: Tue Jul 20, 2010 6:15 am
by buckit
This is the function I use to validate the upload... should get you going.

Code: Select all


function validate_upload($file,$max_size = '3000000'){
	$fileName = $file['name'];
	$fileSize = $file['size'];
	$fileType = $file['type'];
	
	if($fileSize < $max_size){
		if($fileType == "image/pjpeg"
						   || $fileType == "image/jpeg"
						   || $fileType == "image/gif"
						   || $fileType == "image/tif"
						   || $fileType == "application/pdf"
						   || $fileType == "application/msword"
						   || $fileType == "application/vnd.ms-excel"
						   ){
			$path_info = pathinfo($fileName);
			if($path_info['extension'] == 'jpeg'
							   || $path_info['extension'] == 'jpg'
							   || $path_info['extension'] == 'gif'
							   || $path_info['extension'] == 'tif'
							   || $path_info['extension'] == 'pdf'
							   || $path_info['extension'] == 'doc'
							   || $path_info['extension'] == 'xls'
							   || $path_info['extension'] == 'csv'
							   ){
				return TRUE;
			}else{
				return FALSE;
			}
		}else{
			return FALSE;
		}
	}else{
		return FALSE;
	}
}
This function will allow any file that is less than 3mb, has extension of jpeg,jpg,gif,tif,pdf,doc,xls or csv. also checks that the mime type of those files