Upload Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Terukio
Forum Newbie
Posts: 2
Joined: Mon Jul 19, 2010 8:48 pm

Upload Error

Post 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>
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Upload Error

Post 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
Terukio
Forum Newbie
Posts: 2
Joined: Mon Jul 19, 2010 8:48 pm

Re: Upload Error

Post 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."; 

}
}
 
?>
 
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Upload Error

Post 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
Post Reply