Jump to content

[SOLVED] PHP File Upload Script


kyleldi

Recommended Posts

Hi Everyone,

 

So I have this script on my website that processes a form and uploads files to my server that a customer submits.  What i'm trying to do is make my script create a folder with the customer's name and store those files they upload into that folder.  The customer name is a required field, but I'm not sure how to obtain this result.  I want to make sure that the customer folder doesn't contain spaces, so the space is replaced by an underscore or something, and that it just appends to the folder if the customer submits more then one request.  I'm not sure where to start, does anyone have an idea? 

 

<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','date');
pt_register('POST','company');
pt_register('POST','name');
pt_register('POST','address');
pt_register('POST','city');
pt_register('POST','state');
pt_register('POST','zipcode');
pt_register('POST','phonenumber');
pt_register('POST','extension');
pt_register('POST','fax');
pt_register('POST','email');
pt_register('POST','website');
pt_register('POST','instructions');
$instructions=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $instructions);pt_register('POST','quantity');
$file01=$HTTP_POST_FILES['file01'];
$file02=$HTTP_POST_FILES['file02'];
$file03=$HTTP_POST_FILES['file03'];
if($name=="" || $email=="" || $instructions=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($HTTP_POST_FILES['file01']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['file01']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['file01']['name'].", was not uploaded!";
$errors=1;
}
if($HTTP_POST_FILES['file02']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['file02']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['file02']['name'].", was not uploaded!";
$errors=1;
}
if($HTTP_POST_FILES['file03']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['file03']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['file03']['name'].", was not uploaded!";
$errors=1;
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date("")."".$HTTP_POST_FILES['file01']['name'];
$image_list[14] = $image_part;
copy($HTTP_POST_FILES['file01']['tmp_name'], "files/".$image_part);
$image_part = date("")."".$HTTP_POST_FILES['file02']['name'];
$image_list[15] = $image_part;
copy($HTTP_POST_FILES['file02']['tmp_name'], "files/".$image_part);
$image_part = date("")."".$HTTP_POST_FILES['file03']['name'];
$image_list[16] = $image_part;
copy($HTTP_POST_FILES['file03']['tmp_name'], "files/".$image_part);
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="

Link to comment
Share on other sites

Using mkdir before copying the files seems to create the $name directory with no problems, though it won't copy the file(s) to the folder because the header has been sent, though the header is not actually sent.  Is there any way around this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.