trptdblc
asked on
Edit upload form to include SWF file, embed SWF on dynamic page in Dreamweaver
I need to extend my current file upload web form to allow for the inclusion of SWF files. The form and PHP script included here successfully uploads JPEG's-the name to a database and the JPEG to a folder on the server. Dreamweaver then creates dynamic pages on-the-fly which include the pictures and text I've uploaded with this form.
I need an edit for this script and form that will include the ability to upload a SWF file and likewise sent its name to a database in the file to a folder. I would then subsequently need a procedure for Dreamweaver by which dynamically generated pages will include the uploaded SWF files the same way in which they had embeded the text and pictures ( I do this by including a src attribute to the binding for the image file in the mysql record set) .
An example of the type of page I'm looking to produce is here... note the flash slideshow and other dynamic content:
http://www.cityhummer.com/vehicle.asp?v=781488
Thank you.
I need an edit for this script and form that will include the ability to upload a SWF file and likewise sent its name to a database in the file to a folder. I would then subsequently need a procedure for Dreamweaver by which dynamically generated pages will include the uploaded SWF files the same way in which they had embeded the text and pictures ( I do this by including a src attribute to the binding for the image file in the mysql record set) .
An example of the type of page I'm looking to produce is here... note the flash slideshow and other dynamic content:
http://www.cityhummer.com/vehicle.asp?v=781488
Thank you.
<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
<?php
//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$ID=$_POST['ID'];
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("employees") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$ID','$name', '$email', '$phone', 'images/$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
v2,
He's building off this post:
https://www.experts-exchange.com/questions/25027884/Put-a-SWF-file-on-a-dynamically-generated-pages-using-Dreamweaver-and-PHP.html
and probably needs to store just the filename without the .swf extension to implement the above...
He's building off this post:
https://www.experts-exchange.com/questions/25027884/Put-a-SWF-file-on-a-dynamically-generated-pages-using-Dreamweaver-and-PHP.html
and probably needs to store just the filename without the .swf extension to implement the above...
@J: If the filename is stored without the extension, then an additional field would need to be added to the db table for file format and several mods made to his script. It would be easier to use the script and db as is and have the dynamic page do a string search at runtime to determine format and method of output to html.
ASKER
Thank you,
can you suggest where in my existing code your reccomended code should be placed?
can you suggest where in my existing code your reccomended code should be placed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am awardig you the ponts. I know little about coding so it may take forever to get this to work. My grades are for your promptness and obvious expertise. If you get a munuite and can explain all this more simply or could suggest a book or other resourse,great .If not thanks anyway
If you post the code for your page that displays the image/s, I'll work the solution into it with explanatory notes. I'd also need the structure of `employees` database. You can get the structure with the code below:-
<?php
//obviously fill in the db user/pass
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("employees") or die(mysql_error());
$result = mysql_query("DESC employees");
$data = mysql_fetch_assoc($result);
echo '<pre>';
print_r($data);
echo '</pre>';
?>
ASKER
I was able to get this to work myself. Thank you . If possible, the form and it's code included at the top of this post needs an edit to allow the file uload of a swf as well as a jpeg. I can revise the mysql to accept new data ad put a new folder on the server labled flash. If not, thank you anyway.
The tweak below incorporates a string search of $pic for the file format 'swf' and if found, will toggle the upload folder to "flash", else the upload folder will be "images". It also sanitises form data and file name.
<?php
//This gets all the other information from the form
if(!empty($_POST['name'])) {
$ID = $_POST['ID'];
$name = (!get_magic_quotes_gpc()) ? mysql_real_escape_string($_POST['name']) : $_POST['name'];
$email = (!get_magic_quotes_gpc()) ? mysql_real_escape_string($_POST['email']) : $_POST['email'];
$phone = (!get_magic_quotes_gpc()) ? mysql_real_escape_string($_POST['phone']) : $_POST['phone'];
$pic = ($_FILES['photo']['name']);
//filename to lowercase
$new_pic = strtolower($pic);
//replace space chars
$new_pic = str_replace(' ','_',$new_pic);
//strip non alphanumeric characters
$pattern = "/[^a-z0-9_]/";
$new_pic = preg_replace($pattern,'',$new_pic);
//preg_match will return 1 if pic is a swf file
$search_swf = preg_match('/swf/',$new_pic);
$is_flash = ($search_swf > 0) ? true : false;
//This is the directory where images will be saved
$target = ($is_flash) ? "flash/" : "images/";
$target .= $new_pic;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error()) ;
mysql_select_db("employees") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$ID','$name', '$email', '$phone', $target)") ;
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
} else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file. Try using a smaller file size.";
}
}
?>
<form enctype="multipart/form-data" action="add.php" method="POST">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name = "email"><br>
Phone: <input type="text" name = "phone"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
ASKER
To Clarify: I need to upload the file names of a swf and jpeg simultaneously on the same form to seperate fields in mysql and the file themseves to folders on the server...is it a simple mater to just add a second file field to the form? And, the php code must have a prefix for each field they are written to, eg: flash/$flash, images/$images (This will allow a full path to the files to be atached to files on dynamic pages)
Thanks again...
Thanks again...
It will do as you describe for a single file upload only. Sorry, but I'm not prepared to code up a multi-file upload form, it takes too much time.
Open another question if you'd like additional answers.
ASKER
Will do
As far as displaying the swf or jpg image in subsequent pages is concerned, you could conditionally display an image or embedded object (flash) based on the string "images/$pic".
On the page that displays the images, you would insert a flash object as you would normally. Then as the mysql query is outputted to the browser, do a string search for 'swf'. If found, display the flash object, else display an image.
Example code below:
Open in new window