PHP Help!

I am totaly new to PHP and am tring to use PHP to allow visiters to upload and or email me with a Form images files. I have found a premade PHP script that works great but I am not sure how to modify it for all that I need. LOL
I need to do 1 of 2 things.
I am going to have several pages with the Forms and each one will have a different number of upload fields on it. I know exactly how to add more for the upload as the script did show how you do that but don’t know how to add more than the one for the attachments. I either need to find out how to modify the code to allow more than 1 attachment, OR find out if there is a way to have the Uploads go into a folder created when uploaded based on one of the input fields. LOL I hope I am explaining this well enough.
Here is the codes I am using:
the FORM:
Upload Image:

Attach File:

The PHP file:
// check for an attachment if there is a file upload it
if ($attachment_name) {
if ($attachment_size > 0) {
if (!$attachment_type) $attachment_type = “application/unknown”;
$content .= “Attached File: “.$attachment_name.”\n”;
$fp = fopen($attachment, “r”);
$attachment_chunk = fread($fp, filesize($attachment));
$attachment_chunk = base64_encode($attachment_chunk);
$attachment_chunk = chunk_split($attachment_chunk);

// check for a file if there is a file upload it
if ($file_name) {
if ($file_size > 0) {
if (!ereg("/$", $path_to_file))
$path_to_file = $path_to_file."/";
$location = $path_to_file.$file_name;
if (file_exists($path_to_file.$file_name))
$location = $path_to_file.rand(1000,3000).".".$file_name;
$content .= “Uploaded File: “.$location.”\n”;

Any and all help would be GREAT! Please keep in mind that i know almost NOTHING about PHP at this point. I am reading a book on it but haven’t gotten far enough to figure this out myself. LOL

Heidi D

$base_dir = isset($_POST[‘dir’]) ? $_POST[‘dir’] : “”;

if(!move_uploaded_file($_FILES[‘tmp_name’][‘tmp_name’], $base_dir . $_FILES[‘tmp_name’][‘name’])){
$file_upload = FALSE;
echo “File not uploaded

$file_upload = TRUE;
echo “File uploaded!


echo “You current directory to upload too is:” . $base_dir . “
echo ‘’;
echo ‘

echo ‘’;
echo ‘’;
echo ‘’;
echo ‘
Directory to upload to
Needs trailing / to work for example “images/”
File to upload
echo ‘’;

This is a quick and dirty method to upload files. You should use move_uploaded_files. This doesn’t do any checks on the data like your does. But I assume you should be able to alter this file to do that?

The script you are using if practically the same. I don’t know why you can’t add more ‘attachemnts’ but you can ‘images’. They are the same in terms of PHP… it’s what you want to do with them…

Can you explain a bit more? What is the difference between the files you want? Why errors/problems are you coming up against when trying to add new attachments?

LOL I was afraid that I was getting in over my head with this. I started out 3 days ago trying to find a way to let visitors send me files from a web page. I quickly learned that the normal form mail cgi doesn’t do anything but txt files. I need to set up pages that will allow a user to send me 5, 10, 15, and 20 files. I also need an email address, and 3 fields of info for each of the files. I was told that PHP was the way to do this but not knowing anything about PHP myself I can’t write the script. I found several premaid scripts but am finding it hard to get all the files to upload or attach.
It doesn’t matter to much to me if the files (all jpgs or gifs) are uploaded to my server, or sent to me in email, it is just if they are uploaded to the server, I really need a subfolder created for each persons set of files. So I wanted to know if it is possable to add something to this PHP code to create a sub folder inside the default upload folder for the files. Such as using the email they put in to name the folder.
IF this isn’t possable, then how can I add more attachment fields so that it will just email me the files? I tried adding more but I wasn’t sure what to change in the code to refer to the second, third and so on attachments. As in, I tried doing attachment1 and attachment2, but I wasn’t sure what in the set of PHP code to change to refer to that field in the Form. LOL I am sorry if I am confusing, I am just so new to all of this!
Thanks again,
Heidi D

Oh ok :slight_smile:

Well I don’t know how to send files in email with PHP.
What I can do though is create a script that will upload the files to your server (in new folders) and then tell you where the files are.
However, I work so I don’t know if I’ll be able to do it (I might sneak some code in :slight_smile: ). But once I get back from work I’ll do it for you. Shouldn’t be too hard. Just a case of adding loops to work with multiple files.

EDIT: Could you send the file you already have to henderson_luke at hotmail dot com? See if it’s easier just changing that.

Ok done (at work ^_^;)

Please look through the file first and change the settings. Everything that needs to be changed should be commented.

Hope it works with minimal effort/problems

WOW! It is great that you did all that for me! I will put it up and let you know how it works! Thanks so very much!
Anything I can do to repay you?
A link I can put on the upload pages maybe?

Heidi D

Ok, I have it up and I have put in what I could tell to add, but I keep getting that the file type isn’t allowed. I think I may be missing some of the info I should have added but wasn’t sure what to put where. I have it up in .php format adn .txt so that you can see the full code as well at try it!

I am sorry to be a pain! LOL
Thanks so much again!
Heidi D

Hmmmm. Can you CHMOD the toadd/ dir to 777 and then try? I keep getting permission denied errors instead of wrong type of files to upload. And you are trying to upload images right? It won’t accept anything e;se like text files, until you put that mime type in the list. You can get a list of mime types here.

And if you want to put a URL/thanks you can but you don’t ave to =). Just glad I can be of assistance.

I knew that I had done that already but checked to be sure and it is 777 already. LOL Not sure what it could be.

What URL and Name should I use?

Heidi D

Are you able to upload files? I still get permission denied erroors :frowning: But it seems my files are being accepted because they are trying to be uploaded.

No, it still isn’t working for me. I am not sure why at all. I still get that the jpg’s I am trying to upload aren’t allowed types even though I added that.
I have another script that is working to upload, it just doesn’t make a new folder. LOL I can use it though. I just need to learn more about PHP!
Thanks soooo much for all your help!
Heidi D

Can you remove the @ at the start of the mkdirs and tell me when done? I’ll see if there is a problem making a directory to uplaod to… maybe you have it set so that only certain IPs can upload? It’s a long shot but I’m running out of ideas…
Maybe you are trying to upload too large a file? PHP usually only allows a 7mb limit of files, no matter what you want to do. try creating a simple PHP file with <?php phpinfo(); ?> and look for upload limit. See if you can see anything wrong there.

Sorry I can’t be of much use. I am baffled as to why I get my message, and you yours. :S

Ok, I took that out. No, what I am trying to upload is small. Just some sig tag images. LOL Who knows what it is. I haven’t tried it yet since removing this though!
Thanks so much agian for all your help!!

Heidi D