Forum Moderators: coopster

Message Too Old, No Replies

uploading files

for logos

         

Sarah Atkinson

5:23 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



I want sponsors to be able to upload their logo (or e-mail it...e-mail would actualy be most convinent for me)
how do I do this?

kamakaze

6:37 pm on Aug 2, 2005 (gmt 0)

10+ Year Member



Uploading files can get very interesting. First, you need an HTML form to handle the input and then a form handler (I use php) to process the upload.

Here is a sample upload form:


<form enctype="multipart/form-data" action="example.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input name="userfile" type="file" />
<input type="submit" value="Upload" />
</form>

That will generate a form with a browse button so that the user can browse and select the file for upload.

As far as the form handler, do you have knowledge of php or asp?

Sarah Atkinson

3:32 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



i use php

jatar_k

5:05 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> e-mail would actualy be most convinent for me

yeah but doing email attachments is never much fun.

have an upload form to allow the client to upload their logo then save it to some directory on your server where you can download it if needed. You could also have the uploader send you an email that a new logo has been uploaded.

if you really want email then just tell them to send it to you attached to an email. :)

Sarah Atkinson

5:07 pm on Aug 3, 2005 (gmt 0)

10+ Year Member



OK so where do I learn aboult uploaders in php?The book I have doesn't cover it well (there are two more books in the seriese and I think it is covered more in them but my wallet can't aford it.)

jatar_k

5:15 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sarah, you should know by now that crazy book learnin' is not as good as us. ;)

try playing with this one
it needs mysql, it also creates a thumbnail.
It works well and you can play around with it to get the idea of how it works.

[webmasterworld.com...] msg #29

dreamcatcher

5:55 pm on Aug 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And if thats no good, here`s a simple little bit of script to upload a file for you.

File/Dir structure on server:

form.php
upload.php
uploads/

1. Chmod uploads dir to 777 or make sure its writeable.

2. Create a page with this form (from kamakaze`s post) and call it form.php. Note I have take out the uploaded file size.

form.php


<form enctype="multipart/form-data" action="upload.php" method="POST">
<input name="userfile" type="file" />
<input type="submit" name="submit" value="Upload" />
</form>

3. Create another file and call this upload.php. Set a maximum for uploads in bytes. This will process the upload:

upload.php

$max = '1048576'; //== 1MB

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

$name = $_FILES['userfile']['name'];
$temp = $_FILES['userfile']['tmp_name'];
$size = $_FILES['userfile']['size'];

if ($size < $max)
{

if (is_uploaded_file($temp))
{

move_uploaded_file($temp, 'uploads/' . $name);

if (file_exists('uploads/' . $name))
{

echo "File Successfully Uploaded!";

}
else
{

echo "File Not Uploaded";

}
}

}
else
{

echo "File Upload Too Big";

}
}

Hopefully that little code snippet helps you too. I don`t think I missed any braces. LOL.

dc

Stu_Rogers

10:29 am on Aug 4, 2005 (gmt 0)

10+ Year Member



The upload php code provided here is ideal for my project and works fine.

But to take it to the next stage....

How do display "please wait" graphic while the file is uploading?

I have found a few upload progress indicatior scripts (for example, MegaUpload) but they are far too complex for my project. I just want some way to let users know that the webpage is working and their file is uploading.

[edited by: Stu_Rogers at 10:49 am (utc) on Aug. 4, 2005]

bzikofski

10:34 am on Aug 4, 2005 (gmt 0)

10+ Year Member



i think that the best thing you can do here is to add a note:

"Depending on size uploading your file can take up to few minutes. Avoid clicking the UPLOAD button more than once"

...

Stu_Rogers

10:42 am on Aug 4, 2005 (gmt 0)

10+ Year Member



I already have that note on my page, but had hoped I might be able to redirect users to another page (with the please wait animation).

Can anybody see a way to achieve this?

Perhaps javascript?

coopster

1:26 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There is a PEAR package you can either use or glean some code ideas from ...

HTML_Progress [pear.php.net]

dreamcatcher

2:10 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a file upload class on the PHP Scripts Repository that does this very thing. I was looking at it only a few weeks ago.

Go to [phpclasses.org...] and check out the file upload classes.

You will need to register to download but they are free and there are some really useful code snippets.

dc

Sarah Atkinson

3:13 pm on Aug 4, 2005 (gmt 0)

10+ Year Member



What aboult if your form isn't just to upload the file. but also contains a lot of other data which needs prossessing?

dreamcatcher

3:43 pm on Aug 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem Sarah, just create the form as you would normally and access the other data via the $_POST method.

<form enctype="multipart/form-data" action="upload.php" method="POST">
Name: <input type="text" name="name">
E-Mail: <input type="text" name="email">
<input name="userfile" type="file" />
<input type="submit" name="submit" value="Upload" />
</form>

$_POST['name'], $_POST['email'] etc

Sarah Atkinson

4:24 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



Dreamcatcher
Just added the file to the server but It's not working. I did get the uploads folder into the right place but all i get is File Not Uploaded.

Sarah Atkinson

4:47 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



from what I can tell
is_uploaded_file($temp) == true
but it isn't moving the file with the move_uploaded_file