|
-
Apr 23rd, 2007, 04:59 PM
#1
Thread Starter
Member
uploading file
Hi I am sory if make your job hard but please be paitient with me, I didn't know what mean by <php></php> but now i know. the problem the code doesn't show any problem but does not output any thing (not uploding) I did check the php ini file for state of uploading it was 'on' and max_file_size is 2m any way the files which i tried very small, coul you help.
PHP Code:
<html>
<head><title>Upload File</title></head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
//handle the form
if(isset($_POST['submit']))
{
//try to move the upload file
if(move_uploaded_file($_FILES['thefile']['tmp_name'], "../uploads/
{$_FILES['thefile']['name']}")){
print '<p> Your file has been uploaded</p>';
}else
{
//problem
print '<p> the file could not uploaded';
//print message depend on the error
switch($_FILES['thefile']['error'])
{
case 1:
print 'The file exceeeds the upoad _maximum filesize setting in php ini';
break;
case 2:
print 'The file exceeeds the upoad _maximum filesize setting in html form';
break;
case 3:
print 'The file was only patialy uploed';
break;
case 4:
print 'no file uploded';
break;
}
print '</b>.</p>';
}
}
?>
<form action="uplo.php" enctype="multipart/form-data" method="POST">
<p>Upload File using the Form</p>
<input type="hidden" name="MAX_FILE_SIZE" value="30000"/>
<input type="file" name="thefile"/>
</br></br>
<input type="submit" value="Upload"/>
</p>
</form>
</body>
</html>
-
Apr 23rd, 2007, 08:30 PM
#2
Re: uploading file
well, you can't have a line break in a file path. I suppose that could be causing problems.
also, you don't have a "submit" name defined in your form. if you don't have submit defined (using the name parameter), then you can't check for that. it's better to use the REQUEST_METHOD, anyway. you won't have useless variables in your form, either. example:
PHP Code:
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
//upload file
}
?>
<!-- show form -->
it's much simpler.
also, the <br> tag cannot really be expressed as "</br>," that's simply invalid. you can use <br>, or be more compliant and use <br />.
I took your script and switched your check for $_POST['submit'] to my checking for the REQUEST_METHOD and everything worked fine. I also removed the line break from your save-to filepath in the move_uploaded_file() call.
edit: basically, this:
PHP Code:
<html>
<head>
<title>Upload File</title>
</head>
<body>
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
//handle the form
if($_SERVER['REQUEST_METHOD'] == "POST"){
//try to move the upload file
if(move_uploaded_file($_FILES['thefile']['tmp_name'], "upload/{$_FILES['thefile']['name']}")){
print '<p> Your file has been uploaded</p>';
}else{
//problem
print '<p> the file could not uploaded';
//print message depend on the error
switch($_FILES['thefile']['error']){
case 1:
print 'The file exceeeds the upoad _maximum filesize setting in php ini';
break;
case 2:
print 'The file exceeeds the upoad _maximum filesize setting in html form';
break;
case 3:
print 'The file was only patialy uploed';
break;
case 4:
print 'no file uploded';
break;
}
print '</b>.</p>';
}
}
?>
<p>Upload File using the Form</p>
<form action="upload.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000"/>
<input type="file" name="thefile" />
<br /><br />
<input type="submit" value="Upload" />
</form>
</body>
</html>
Last edited by kows; Apr 23rd, 2007 at 08:34 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|