Beginner with Yahoo web hosting and PHP questions

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
jswalt
Forum Newbie
Posts: 6
Joined: Mon Jul 06, 2009 9:27 am

Beginner with Yahoo web hosting and PHP questions

Post by jswalt »

I am a complete beginner when it comes to web design. I can barely get by with html code, and have been playing with PHP scripts recently. I was trying a piece of code I came across and can't seem to get it to work. I am wondering if it is Yahoo that is causing the problem or the code itself. I am wanting to implement a file upload field to my contact form and am when the PHP file tries to run, it just shows the PHP code itself in the web browser window. Below is my html code...followed by my PHP script.

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

$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!";
}

I have created the PHP file in the root directory of the Yahoo file manager section. I have also created a "uploads/" folder. I tried changing this folder to "tmp" along with the reference in the PHP file, but can't get anything to work. I hate to be banging my head against a wall if Yahoo is what is keeping file upload feature from working. Any help would be appreciated. Thanks in advance.
jswalt
Forum Newbie
Posts: 6
Joined: Mon Jul 06, 2009 9:27 am

Re: Beginner with Yahoo web hosting and PHP questions

Post by jswalt »

I did talk to Yahoo a little while ago and they said that I should be able to do what I am trying to do. They have limits in place for maximum file size and duration that the PHP file can run, but I should be under those limits with the test file that I have been playing with. It must be something I am doing wrong in the PHP file itself or the directory structure that I have in Yahoo. If anyone has any ideas, please let me know. Thanks.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Beginner with Yahoo web hosting and PHP questions

Post by califdon »

If what you posted is literally what you have in your file, it is not working because you are never telling the web server that you want it to parse the PHP. Every time you want to use PHP code, you must use opening
<?php
and closing
?>
tags. Probably your code should look like this:

Code: Select all

<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>
<?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!";
}
?>
jswalt
Forum Newbie
Posts: 6
Joined: Mon Jul 06, 2009 9:27 am

Re: Beginner with Yahoo web hosting and PHP questions

Post by jswalt »

I told you I was a beginner...I think that took care of part of my problem. It appears to be functioning somewhat correctly now. Sorry about that...still learning the basics. Thanks for helping out with that...I know it can be frustrating working with someone that misses the obvious things. :banghead:

I haven't had much time to play with the file yet, but once I upload it to yahoo, I can't seem to access the file from Yahoo file manager. I can see that it is there, but it won't let me open it or do anything with it. It's possible I have it password protected, but it doesn't prompt me to enter any password information and I thought I had the folder set to public.

My next steps after I figure out why I can't access the file will be to add the ability to upload more than one file at a time...and to add some basic security features into the code to keep things realatively safe from trouble-makers. Any help on these issues would be appreciated as well. Thanks again.
jswalt
Forum Newbie
Posts: 6
Joined: Mon Jul 06, 2009 9:27 am

Re: Beginner with Yahoo web hosting and PHP questions

Post by jswalt »

Ok, figured out how to get my file that I uploaded now...used ftp and was able to manipulate the file as I should. I have been playing with multiple file selection fields and think I have the html portion down ok by giving each input field a different name. However, I haven't been able to figure out how to get the PHP file to deal with each of the different names. I am sure I just haven't put the names in the correct location of the PHP file, but have tried multiple ways of doing it without success. Any help with this and with suggestions on setting up the PHP file to be more secure would be greatly appreciated.

My html code is as follows:

<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="uploadedfile1" type="file" /><br />
Choose a file to upload: <input name="uploadedfile2" type="file" /><br />
Choose a file to upload: <input name="uploadedfile3" type="file" /><br />
Choose a file to upload: <input name="uploadedfile4" type="file" /><br />
Choose a file to upload: <input name="uploadedfile5" type="file" /><br />

<input type="submit" value="Upload File"
/>
</form>


My PHP code is as follows:

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile1']['name']);
if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile1']['name']).
" has been uploaded";

} else{
echo "There was an error uploading the file, please try again!";
}
?>
Post Reply