Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

File Uploading Issues

Recommended Posts

i have never tried to have files uploaded and i am still not able to do so. here is the codes that i am using right out of the php manual and it still isnt working. i have also listed the warnings/errors listed on the resulting page. my permissions are set to 777 also. i have a folder set up on my server as "uploads". i am however not sure if i have a default temp folder on my server. can anyone help me figure out what i am not doing correctly or what my next step is?

this is the form that i am using:
html Code:

<form enctype="multipart/form-data" action="upload.php" method="post">    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />    Choose a file to upload: <input name="userfile" type="file" />    <input type="submit" value="Upload File" /></form>


this is the php page "upload.php"
php Code:


# #<?php#$uploadDir = '/uploads/';#$uploadFile = $uploadDir . $_FILES['userfile']['name'];#print "<pre>";#if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFile))#{#    print "File is valid, and was successfully uploaded. ";#    print "Here's some more debugging info:\n";#    print_r($_FILES);#}#else#{#    print "Possible file upload attack!  Here's some debugging info:\n";#    print_r($_FILES);#}#print "</pre>";#


this is the resulting error:
Code:

Warning:  move_uploaded_file(/uploads/golf.jpg): failed to open stream: No such file or directory in /home/jesokcc/public_html/upload.php on line 5Warning:  move_uploaded_file(): Unable to move '/tmp/php72OLgu' to '/uploads/golf.jpg' in /home/jesokcc/public_html/upload.php on line 5Possible file upload attack!  Here's some debugging info:Array(    [userfile] => Array        (            [name] => golf.jpg            [type] => image/pjpeg            [tmp_name] => /tmp/php72OLgu            [error] => 0            [size] => 9802        ))

Thanks,kvarnerexpress

Share this post


Link to post
Share on other sites

It looks like your code is valid and should work. On what kind of server are you running this script? (i.e., Linux, Windows, et cetera) You may simply have a permissions problem that either you or the server administrator needs to change. That's all of which I can think!Hope this helps!!

Share this post


Link to post
Share on other sites

Try changing $uploadDir = '/uploads/'; to $uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';

 

As it is now, PHP will try and copy the uploaded file into the '/uploads' directory on the root of the server - not the root of your site, which is probably something like '/www/username/public_html/'.

Share this post


Link to post
Share on other sites

I'm also just trying out file uploads myself. Having some issues though. using the example from php website: http://nz2.php.net/features.file-upload

but I'm getting this error with some missing values:

Possible file upload attack!Here is some more debugging info:Array(	[userfile] => Array		(			[name] => 01aa.jpg			[type] => 			[tmp_name] => 			[error] => 6			[size] => 0		))

any help appreciated ^^


<html>	<head>		<title></title>	</head>	<body>			<!-- The data encoding type, enctype, MUST be specified as below -->	<form enctype="multipart/form-data" action="uploader.php" method="POST">		<!-- MAX_FILE_SIZE must precede the file input field -->		<input type="hidden" name="MAX_FILE_SIZE" value="30000" />		<!-- Name of input element determines name in $_FILES array -->		Send this file: <input name="userfile" type="file" />		<input type="submit" value="Send File" />	</form>		</body>  </html>


<?php// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead// of $_FILES.$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';;$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);echo '<pre>';if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {	echo "File is valid, and was successfully uploaded.\n";} else {	echo "Possible file upload attack!\n";}echo 'Here is some more debugging info:';print_r($_FILES);print "</pre>";?>

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

Yeah I had a error code of 6. I looked at the php.net documentation and found out it was because I was missing a temp location setting in php.ini so I set that and it works. Changed the code a bit but its working now. I just need to find ways to secure and check files being uploaded.

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.