The intent of this form is to create a folder for a client and upload an image into another folder 'imagesClients'. The form works as follows:
Username: selected from drop down menu.
Folder: Slide shows will be FTP to folder. Repeat clients may have more than one folder. Uploaded images will not go into this folder.
Image: Selected from window
Active: Either yes or no
mkdir works without any problems.
Here are my issues:
1. image doesn't upload to 'imagesClients' folder.
2. image name isn't uploading to the db.
3. how would I add a file validation to 'if(!$user || !$folder || !$active)'. I tried creating a variable for 'file' but received an undefined error.
3. I'm self taught through a dummies book, am I doing this right or is there a better method?
Thanks in advance!!
slideshow_new.php
Code: <?php
session_start();
error_reporting(E_ALL);
require_once('site_fns.php');
include("connect.php");
do_html_header('New Client');
do_menu_main2('');
check_login();
do_mainadmin_menu('');
if(!$_POST['submit']) // 'submit' hasn't been clicked so output html.
{
//set up form options to select a username
$sql = mysql_query("SELECT DISTINCT username FROM Client");
while($row = mysql_fetch_assoc($sql))
{
$dd .= "<option value='{$row['username']}'>{$row['username']}</option>";
}
?>
<form enctype="multipart/form-data" action="slideshow_new.php" method="post">
<fieldset>
<legend>Setup Slideshow</legend>
<ol>
<li>Select: <select name="username" style="width: 222px;">
<? echo $dd; ?></select></li>
<li>Folder Name: <input type="text" name="foldername" /></li>
<li><input type="hidden" name="MAX_FILE_SIZE" valude="10000000" />
Client Image: <input type="file" name="file" id="file"/></li>
<li>Active Image: <select name="active">
<option value="yes" selected="selected">Yes</option>
<option value="no">No</option></select></li>
<input type="submit" name="submit" value="Add Slideshow" />
</ol>
</fieldset>
</form>
<?php
}
else
{
$clientusername = protect($_POST['username']);
$folder = protect($_POST['foldername']);
$active = protect($_POST['active']);
$errors = array();
if(!$user || !$folder || !$active)
{
$errors[] = "You did not fill out the required fields.";
}
//Ensure client folder doesn't exist. Creates client folder
$sql = "SELECT * FROM Slideshow WHERE (foldername) = ('$folder')";
$query = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($query) > 0)
{
$errors[] = "Folder name is already in use, please try another";
}
else
{
mkdir("/home/brittao1/public_html/Clients/$folder", 0700);
}
//This function will upload your file
function upload()
{
//Collect all info into variables
$file = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$temp = $_FILES["file"]["tmp_name"];
$imageSize = getimagesize($temp);
//If file size is bigger than 1mb display error
if($imageSize > 1000000)
{
$errors[] = "File size must be less than 1MB.";
}
//Check allowed file types
if (preg_match('/image/(jpg|jpeg|gif|png)/', $imageSize['mime']))
{
if (file_exists("/home/brittao1/public_html/imagesClients/$file"))
{
$errors[] = "$file image already exists.";
}
else
{
//If everything is good then let's upload
move_uploaded_file($temp, "/home/brittao1/public_html/imagesClients/$file");
}
else
{
$errors[] = "File type must be .jpg, .jpeg, .gif, or .png.";
}
}
}
if(count($errors) > 0)
{
echo "<h1>The following errors occured with your slideshow.</h1>";
echo "<div class='error'>";
foreach($errors AS $error)
{
echo $error . "<br />";
}
echo "</div>";
echo "<a href="javascript:history.go(-1)">Try again</a>";
//we use javascript to go back rather than reloading the page
// so the user doesn't have to type in all that info again.
}
else
{
//upload to database
$sql = "INSERT INTO Slideshow (username, foldername, active, image_name)
VALUES ('$clientusername','$folder', '$active', '$file')";
$query = mysql_query($sql) or die(mysql_error());
echo "</ br><div class=bodyText>Slideshow folders prepared for $clientusername.<br />
FTP lightroom slideshow to $folder folder.</div>";
}
}
do_html_footer();
?>
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.I guess this is because of the loose typing of PHP,
Just cannot get 'area' to submit to db using same php code as already used
Basically all i have done is just modified some code and added an area section.The form is allready submitting other things like location price etc.And i have simply added a field in db called area
Help: problem with Headers to download PDF file
Hi,I'm trying to implement a script where when a user clicks a link he gets a PDF file to open or save.In my index.php page I have the following link:Code: <a
Downloading file (Headers)
I'm trying to make users download a file, but they must wait 60 seconds before it begins.But, I'm stuck - the file isn't downloading, and no error is being shown (I've enabled E_ALL error
in php, link returns to the line
When I add a link in a php page, the link word returns to the line (as a would do)Example:<a href="#">like</a></td> <td><a
Date help - fetch dates for Mondays between xxx and yyy?
Does anyone know the best way to do this? I have two dates, say:2010-01-26 and 2010-05-30and I want to return the dates of all the Mondays between them:2010-02-012010-02-082010-02-15....etc.Thanks
Insert Failing.
Hey,I am making a Sign up page for a website, but the insert query into the Database does not seem to work, it returns no errors, just simply does not work.Code: $insert_user =
Operator precedence assistance.
I did a quick Google search and couldn't quite find the answer I wanted in terms I could understand, so, if I may, I'd like to ask quite a specific question.I'm creating a contact form, and I need to
php multiple action on submit
I have a form which says:<form enctype='multipart/form-data' method='post' action='process.php' target='_blank'>I need to call process.php on submit or on clicking submit button. Now
PHP Code reffering to database, doing something wrong.. pls help
Well i am quite new with PHP and for school we have to make a PHP script which reffers to a Database,Well, more explicit, we have this form showing all "employees"last name etc. made it week