Jump to content

[SOLVED] upload form


aebstract

Recommended Posts

Hello,

I am trying to write a simple upload script, I will be making it a lot more involved later on, for now I just want it to work. The php code seems to cause nothing on the page to display:

 

upload.php

<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) {

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) {

	print 'Your file has been uploaded.';

} else {

	switch ($_FILES['thefile']['error']) {
	   case 1:
	   	print 'The file exceeds the upload_max_filesize setting in php.ini';
		break;
	   case 2:
	   	print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form';
		break;
	   case 3:
	   	print 'The file was only partially uploaded';
		break;						
	   case 4:
	   	print 'No file was uploaded';
		break;
	}
}
}

?>

 

www.hillmarketinggroup.com/upload.php

 

If anyone can tell me what is wrong/causing this that would be great. Also, I am not sure if this does it or not, but I will be wanting to change the filename when it is uploaded. That is possible, right?

Thanks!

Link to comment
Share on other sites

Uhg sorry, I thought I posted the entire code for the page, and I just put up the php:

This is what I have..

 

 

 

upload.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>upload mailers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST['submit'])) {

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}")) {

	print 'Your file has been uploaded.';

} else {

	switch ($_FILES['thefile']['error']) {
	   case 1:
	   	print 'The file exceeds the upload_max_filesize setting in php.ini';
		break;
	   case 2:
	   	print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form';
		break;
	   case 3:
	   	print 'The file was only partially uploaded';
		break;						
	   case 4:
	   	print 'No file was uploaded';
		break;
	}
}
}

?>



<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="thefile" />
<input type="submit" value="upload" />
</form>


</body>
</html>

 

 

The page being blank IS the problem. The form isn't showing up?

Link to comment
Share on other sites

Okay that was the problem, thanks for spotting that. Moving along:

 

I took out the ../ and made a folder called uploads in the same directory that that file is located. I tryed the form, nothing is happening (the error messages aren't saying that it uploaded or errored and nothing is being uploaded)

Link to comment
Share on other sites

Permissions are set to 777, the folder is uploads which is located in the main directory, same directory as the upload.php file.

 

1 files and directories in hillmarketinggroup.com / httpdocs / uploads total

 

Thats the uploads folder found in the directory and upload.php is in httpdocs.

With all of that said, how is this line wrong?

 

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "uploads/{$_FILES['thefile']['name']}")) {

 

I want it in the uploads folder, what would I put in front of uploads, if its in the main dir?

 

Link to comment
Share on other sites

Okay I tryed:

 

 

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "/httpdocs/uploads/{$_FILES['thefile']['name']}")) {

 

and

 

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "hillmarketinggroup.com/httpdocs/uploads/{$_FILES['thefile']['name']}")) {

 

and

 

if (move_uploaded_file ($FILES['thefile']['tmp_name'], "hillmarketinggroup.com/uploads/{$_FILES['thefile']['name']}")) {

 

 

none are doing anything, just basically brings me back to the form. What I don't get is why it isn't telling me the reason it isn't uploading. Is there any code I can add on to that line to see if there are any errors coming out of it?

Link to comment
Share on other sites

Please go and check your php.ini.

 

check

 

post_max_size

upload_max_filesize

 

if the file you upload is exceed upload_max_filesize or post_max_size, then upload process will be terminate automatically.

 

and

 

<input type="hidden" name="MAX_FILE_SIZE" value="30000" />   

 

should be removed from your upload page, if you have read through upload file section, you will know that php don't recognize MAX_FILE_SIZE during upload process (strange thing is the example in www.php.net use this hidden input box ??!! ).

 

 

Link to comment
Share on other sites

Well I was using the PHP for the world wide web book to make the form, theres a section on it. I went through and checked all that with my php.ini, which can be found at: www.hillmarketinggroup.com/phpinfo.php also they say to use the hidden field for some reason. Even if my file size I am trying to upload is too big, wouldn't the error message display??

Link to comment
Share on other sites

I can tell you that you cannot control client site. Try not to believe all the data come from browser.

 

ya, they also told me to use the hidden field for some reason, after that I had spent two days three nights to solve this problem, finally I come out with not to use this hidden field.

 

Maybe your book is good, but not always right.

 

The error message display, sometimes don't work on php, maybe bugs,settings, error msg disable  blah blah blah.....

 

 

Link to comment
Share on other sites

move_uploaded_file ($FILES['thefile']['tmp_name'], "../uploads/$_FILES['thefile']['name']}"))

 

I see. In sentence above what is $FILES ? It should be $_FILES.

 

I have tested the code I wrote just now. It should work for you also. Save it to test.php, then run it and see how....

[


<?php
       print_r($_FILES);
        if (move_uploaded_file($_FILES['thefile']['tmp_name'],  "../uploads/".$_FILES['thefile']['name'])) {
        }
        else{
             echo "Error";
        }
?>
<form action="test.php" enctype="multipart/form-data" method="post" >
<input type="file" name="thefile" />
<input type="submit" value="upload" />
</form>

]

 

 

 

 

 

Link to comment
Share on other sites

sorry. One's home work should be done by oneself.

 

Moving the file from /tmp/php15QnkE to /uploads/$_FILES['thefile']['name'] folder doesn't seems too challenging to you. I know you can do it by yourself. hei,hei.

 

why don't you hard code your path and filename for testing (using absolute path)?

Link to comment
Share on other sites

Maybe cause I have no clue what you're even talking about and if I came to forums to get help, I don't expect to be told to go figure it out on my own. I figure help forums would help me get the problems fixed, not leave me with them basically where I started at...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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