Jump to content

PHP Upload Help


cozmir

Recommended Posts

Hi,

I am using the existing upload script and would like to add the ability to have the files drop into a directory based on the name chosen from the drop down list on the form. Currently all files drop into the same directory all the user is notified via email. I want to keep the email notification ability. I'm new to PHP and any help is greatly appreciated. Thanks!

 

Uploader Script...

 

<?php

session_start();

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

$files = array();

$errors = array();

foreach($_FILES as $f) {

if($f['error'] == UPLOAD_ERR_OK) {

$ts = time();

$filename = $ts . '-' . preg_replace('/[^a-zA-Z0-9_\.-]/', '', $f['name']);

$ok = move_uploaded_file($f['tmp_name'], '/upload/files/' . $filename);

chmod('/upload/files/' . $filename, 0644);

$files[] = $filename;

} else {

switch($f['error']) {

case UPLOAD_ERR_INI_SIZE:

case UPLOAD_ERR_FORM_SIZE:

$errors[] = $f['name'] . ' could not be uploaded because the filesize is too large.';

break;

case UPLOAD_ERR_PARTIAL:

$errors[] = $f['name'] . ' could not be uploaded because the upload could not be completed.';

break;

}

}

}

foreach($_POST as $k => $v) {

$$k = stripslashes($v);

}

$file_paths = '';

foreach($files as $file) {

$file_paths .= "$file\n";

}

$mail_to = array_pop(explode(' - ', $notify));

$message .= "Company Name: $company_name\n";

$message .= "Name: $name\n";

$message .= "Contact Phone: $contact_phone\n";

$message .= "Contact Email: $contact_email\n";

$message .= "Name of Advertiser: $name_of_advertiser\n";

$message .= "Comments: $comments\n\n";

$message .= "Files:\n" . $file_paths . "\n";

$ok = mail($mail_to, "File Upload", $message);

if($ok && empty($errors)) {

$_SESSION['msg'] = 'Your files were successfully uploaded.';

} else {

$_SESSION['msg'] = implode('<br />', $errors);

}

header('Location: upload_confirm.php');

exit;

} else {

header('Location: index.php');

exit;

}

?>

 

 

Form Code...

 

<form action="upload_process.php" method="post" enctype="multipart/form-data" onSubmit="return validate_form(this);" />

<table align="center">

<tr>

<td align="right" valign="top"><p>Your Company</p></td>

<td valign="top"><input type="text" size="55" name="company_name" value="" /></td>

</tr>

<tr>

<td align="right" valign="top"><p>Name</p></td>

<td valign="top"><input type="text" size="55" name="name" value="" /></td>

</tr>

<tr>

<td align="right" valign="top"><p>Phone</p></td>

<td valign="top"><input type="text" size="55" name="contact_phone" value="" /></td>

</tr>

<tr>

<td align="right" valign="top"><p>Email</p></td>

<td valign="top"><input type="text" size="55" name="contact_email" value="" /></td>

</tr>

<tr>

<td align="right" valign="top"><p>Advertiser</p></td>

<td valign="top"><input type="text" size="55" name="name_of_advertiser" value="" /></td>

</tr>

<tr>

<td align="right" valign="top"><p>Please Notify</p></td>

<td valign="top">

<select name="notify">

<option value=''></option>

<option value="test - [email protected]">Testing</option>

<option value="test2 - [email protected]">Testing 2</option>

<option value="test2 - [email protected]">Testing 3</option>

 

</select>

</td>

</tr>

<tr>

<td align="right" valign="top"><p>File Uploads</p></td>

<td valign="top"><br />

<p>File 1:<input type="file" name="file1" /></p> <br />

<p>File 2:<input type="file" name="file2" /></p> <br />

<p>File 3:<input type="file" name="file3" /></p> <br />

</td>

</tr>

<tr>

<td align="right" valign="top"><p>Comments</p></td>

<td><textarea name="comments" rows="10" cols="40"></textarea></td>

</tr>

<tr>

<td> </td>

<td><input type="submit" id="_submit" name="_submit" value="Upload" /></td>

</tr>

</form>

 

          </table><br/><br/>

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/78944-php-upload-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.