Forum Moderators: coopster

Message Too Old, No Replies

New to PHP and wish to use a upload coding

         

chubbymouse

3:33 pm on Feb 11, 2006 (gmt 0)

10+ Year Member



I'm new to PHP and wish to use a upload files coding on my site as part of a form but I have know idea where to start.

I've tried using tutorials on Google and they just confuse me, my knowledge of PHP is very limited

dreamcatcher

6:25 pm on Feb 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi chubbymouse and welcome to Webmaster World.

You might find this thread useful:
[webmasterworld.com...]

In particular msg #29 by Birdman.

dc

chubbymouse

8:41 pm on Feb 11, 2006 (gmt 0)

10+ Year Member



No not really but thanks. I have the form set out in HTML I just need to know what to do next and the coding to make it be delivered to my server. I read somewhere you needed an "action page" how and what is this.

What would the coding be?

newb

12:07 am on Feb 12, 2006 (gmt 0)

10+ Year Member



<?php

// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];

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

<html>
<head>
<title>Uploader</title>
</head>
<body>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

make a folder name call "uploads"
chmod 777 or 707
save this file name call upload.php for example

chubbymouse

12:23 am on Feb 12, 2006 (gmt 0)

10+ Year Member



So the top part goes on the same or separate pages? lol
Hmm I think I've got it but I'll test it soon lol

chubbymouse

2:44 am on Feb 12, 2006 (gmt 0)

10+ Year Member



Is that all done or do I still have to change some values around?

newb

10:37 am on Feb 12, 2006 (gmt 0)

10+ Year Member



done!
just copy all the code above then put it into a file whatever you call it like uploader.php.
all in one file not 2

chubbymouse

12:05 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



You are a legend, I will get on it straight away.

Just one last question does the top part go inbetween the head tags or in the body next to the form?

chubbymouse

12:46 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



Right I've got it to work but am not getting the files to the uploads folder on my server

newb

10:37 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



You need to change permission folder "uploas" to 777 or 757 or 707

[edited by: newb at 10:41 pm (utc) on Feb. 12, 2006]

newb

10:41 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



uploader.php
--------------
here i made another one for ya

<html>
<head>
<title>Uploader</title>
</head>
<body>
<form enctype="multipart/form-data" action="" method="POST">
<p align="center">
<input type="hidden" name="MAX_FILE_SIZE" value="" />
Choose File you need to upload from your PC:</p>
<p align="center">
&nbsp;<input name="uploadedfile" type="file" /><br>
<br />
<input type="submit" value="Upload File" />
</p>
</form>
<p align="center">
<?php

// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "File ". basename( $_FILES['uploadedfile']['name']). "Your file is Uploaded" ;
} else{
echo "<!-- error-->";
}
?>
</p>
</body>
</html>

chubbymouse

12:11 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Yea I CHMODed to 777 but I stilll didn't recieve it.

I'll try the other one

chubbymouse

1:19 am on Feb 13, 2006 (gmt 0)

10+ Year Member



Am I doing something wrong lol:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<link rel="shortcut icon" href="http://www.example.co.uk/images/favicon2.bmp">
<!--StartFragment -->
<title>200m Peanut</title>
<link href="Style.css" type="text/css" rel="stylesheet" />
<style type="text/css">
<!--
.style44 {
font-family: "Arial Narrow";
font-weight: bold;
color: #000000;
font-size: 16px;
}
.style45 {
font-family: "Arial Narrow";
font-size: 14px;
}
.style46 {font-size: 16px}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#000000" vlink="#000000" alink="#000000" >
<div align="center" class="style44"> </div>
<p align="center" class="style45 style46"><strong>Send us a Graphic</strong>
<p align="center" class="style45">Got a graphic your especially proud of? Want to show your artistic design handywork to the example Team then look no further
<p align="center" class="style45">Just use the form below and your fantastic graphic will come directly to me.
<p align="center"><center><FORM action= http://example.co.uk/cgi-sys/FormMail.cgi method=post>
<div align="center">
<INPUT type=hidden value= admin@example.co.uk name=recipient>
<INPUT type=hidden value="Upload" name=subject>
<INPUT type=hidden value="name,email," name=required>
<INPUT type=hidden value=http://www.example.co.uk/index.php?go=Confirmation4 name=redirect>

<form method="post" action="photoupload.asp" name="submit" enctype="multipart/form-data">

<div align="center">
<p align="center">Name:
<input type="text" name="name">
</p>
<div align="center">Email:
<input type="text" name="email">
</div>
<p>
<form enctype="multipart/form-data" action="" method="POST">
<p><form enctype="multipart/form-data" action="" method="POST">
<p align="center">
<input type="hidden" name="MAX_FILE_SIZE" value="" />
Choose file you need to upload from your PC:</p>
<p align="center">
&nbsp;<input name="uploadedfile" type="file" /><br>
<br />
<input type="submit" value="Upload File" />
</p>
</form>
<p align="center">
<?php

// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "File ". basename( $_FILES['uploadedfile']['name']). "Your file is Uploaded" ;
} else{
echo "<!-- error-->";
}
?></p>
<p align="center">Coding if it’s a grapic:</span><br>
<textarea cols=25 rows=6 name="comments">Put the coding in here for a graphic. The graphic will be uploaded to our server </textarea>
</p>
<p align="center">Thankyou for your contribution.
<p align="center"><input type="reset" value="Clear">&nbsp;&nbsp;
<input type="submit" value="Upload File" />
</form></center>
<br>
<br>

</p>
</div>
</form>
<br />
</div>

<p align="center"></form>
</center>
</body>
</html>
</p>
</body>
</html>
</p>
</body>
</html>
</p>
<p>&nbsp;&nbsp; </p>
</body></html>

[edited by: jatar_k at 6:15 pm (utc) on Feb. 13, 2006]
[edit reason] examplified url [/edit]

newb

10:59 pm on Feb 13, 2006 (gmt 0)

10+ Year Member



<form method="post" action="photoupload.asp" name="submit" enctype="multipart/form-data">

this is such a messy code

chubbymouse

11:51 am on Feb 18, 2006 (gmt 0)

10+ Year Member



Lol, you can tell I'm a beginner at PHP:
I now also have a new problem, I want a code that lets me change the skin of my site when a user clicks it. I've searched endlessly on the internet trying to find one and even contacted various site owners about me seeing their code but to no avail.
I only wish for a simple script that changes the colours nothing fancy, just something to give variation.
If and when you have time could you give this a run over please :)