|
-
Jan 21st, 2009, 05:23 PM
#1
Thread Starter
Frenzied Member
Upload File PHP
Hello i am using the following code:
announcement.html:
Code:
<form enctype="multipart/form-data" action="uploader.php" method="POST"^gt;
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
Upload File: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>
uploader.php:
Code:
$target_path = "uploads/";
$target_path = $target_path . basename(
$_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'],
$target_path)) {
echo “The file “. basename(
$_FILES['uploadedfile']['name']). ” has been uploaded”;
} else{
echo “There was an error uploading the file, please try
again!”;
}
This is not currently on a server, i will upload it later. At the moment i am running this off my computer. When i click upload after i select my file internet explorer prompts me to download the file uploader.php .
I want the code in that file to take action i don't want to download it. What is wrong?
Last edited by noahssite; Jan 21st, 2009 at 07:04 PM.
-
Jan 21st, 2009, 05:26 PM
#2
Re: PHP wont work...
you need PHP running on a server of somekind.... even if it's your local machine... for quick and easy installation I suggest XAMPP (or LAMPP for Linux, what ever boats your float).
http://www.apachefriends.org/en/xampp.html
I've got it installed onto a flash drive so I can take my test server where ever I go.
-tg
-
Jan 21st, 2009, 06:41 PM
#3
Thread Starter
Frenzied Member
Re: PHP wont work...
thanks also with the code of uploader.php changed to:
Code:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
When i try to upload an image file or at least i havnt tried any other type, it always displays the error, There was an error uploading the file, please try again!...
What is wrong? Is there something off in the code?
-
Jan 21st, 2009, 07:05 PM
#4
Thread Starter
Frenzied Member
Re: Upload File PHP
Do some hosting providers disable the ability to upload?
-
Jan 21st, 2009, 08:37 PM
#5
Re: Upload File PHP
Not that I am aware of... I've never had a problem with my host at least.
Unfortunately I've never tried to upload a file via PHP, so I'm a little out of my element at this point... sorry.
-tg
-
Jan 22nd, 2009, 07:23 AM
#6
Thread Starter
Frenzied Member
Re: Upload File PHP
Then it may just be something wrong with my code?
How can that be since i got it off a php tutorial...
-
Jan 22nd, 2009, 08:20 AM
#7
Hyperactive Member
Re: Upload File PHP
I know this may sound like a dumb question but is the file you are trying to upload over the max file size that you specified? Also, not sure why but on you form line I se ^gt; instead of > it shoud be:
Code:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />
Upload File: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>
If I helped you please rate me.
-
Jan 22nd, 2009, 06:59 PM
#8
Thread Starter
Frenzied Member
Re: Upload File PHP
I was actually changing my code a bit and i got my code from different sources. Here is my latest code i am using i am not sure if it is any different then the code i have shown above.
announcement.html
Code:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
uploader.php
Code:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
EDIT:
I think the uploading is fine but not the move_uploaded_file part...
Since i have been testing the feature with pictures and text files but when i tried a flash file it took a while longer untill the error message appeared..
-
Jan 22nd, 2009, 07:15 PM
#9
Thread Starter
Frenzied Member
Re: Upload File PHP
I even tried the code on this page (tutorial):
http://www.w3schools.com/PHP/php_file_upload.asp
It is fine with puting the file in the temp folder as i thought. Though there is an issue with uploading.
-
Jan 22nd, 2009, 08:18 PM
#10
Thread Starter
Frenzied Member
Re: Upload File PHP
Maybe it does come back to a server issue? i will see if my server doesn't support uploading... i don't understand why it wouldn't.
EDIT:
To prevent posting 4 times in a row im just adding another question into this post.
Could it be that i have to enable directory permissions on my hosting provider?
Last edited by noahssite; Jan 22nd, 2009 at 10:01 PM.
-
Jan 23rd, 2009, 07:15 AM
#11
Re: Upload File PHP
yes, your script will need to have write permissions for whatever folder you're moving files to.
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
|