logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-10-2008, 09:07 AM   #1
student101
 
Join Date: Dec 2007
Posts: 379
Question uploading-files?

This tut:
http://www.dreamweaverclub.com/vtm/uploading-files.php
Trying the type parts, but no luck?
PHP Code:
session_start();
if(isset(
$_POST['uploader'])){
if (
$_FILES['uploadedfile'] == '')  {
      
$error '<strong><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Nothing submitted?</font></strong><br>';
} else {
if (
"type" != "image/gif") {
    
$error '<font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Error in upload type</font>';
} else {

echo 
"<pre>";
print_r($_FILES);
echo 
"</pre>";

$target_path "C:/Documents and Settings/Jay/My Documents/sites/jtechsystems-php/upload/".$_FILES['uploadedfile']['name'];
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
}
}

Any ideas?
student101 is offline   Reply With Quote
Old 03-10-2008, 09:14 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

what are the type parts

this is a vague question
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-10-2008, 09:28 AM   #3
student101
 
Join Date: Dec 2007
Posts: 379
Default

Ok,
So how do I add this file type pattern instead?
PHP Code:
$pattern="\.(jpg|jpeg|png|gif|bmp)$"
Only allow these types of files?
student101 is offline   Reply With Quote
Old 03-10-2008, 12:40 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

ok

i understand

i think it would be a good idea to use a switch to id your mime types

PHP Code:
 
if(isset($_POST['uploader'])){
 
  if (
$_FILES['uploadedfile'] == '')  {
 
      
$error '<strong><font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Nothing submitted?</font></strong><br>';
  } else {
 
     if (
"type" != "image/gif") {
 
    
$error '<font color="#FF0000" size="2" face="Verdana, Arial, Helvetica, sans-serif">Error in upload type</font>';
 
     }else{
 
          echo 
"<pre>";
          
print_r($_FILES);
          echo 
"</pre>";
 
  
$target_path "C:/Documents and Settings/Jay/My Documents/sites/jtechsystems-php/upload/".$_FILES['uploadedfile']['name'];
 
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
 
        }
   }

ok

this is the bit that determins the mime type of the file you have uploaded

PHP Code:
if ("type" != "image/gif"

ok we are going to replace the condition with a boolean true/false

above the IF you add a switch..
PHP Code:
switch($_FILES["uploadedfile"]["type"]){
 
case 
'image/gif'$type true; break;
case 
'image/jpg'$type true; break;
case 
'image/png'$type true; break;
 
/// add the rest yourself 
 
}
 
/// the IF below replaces the IF above ///
if ($type == true) { /// etc 
mime types...
http://www.webmaster-toolkit.com/mime-types.shtml

you can use the above or use an array to store the mime types

if you work out a method which uses an array ill award you with a DWC medal

it has to work though
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-10-2008, 12:42 PM   #5
student101
 
Join Date: Dec 2007
Posts: 379
Default I have got no clue on how or what goes where?

Quote:
Originally Posted by davidj View Post
what are the type parts
this is a vague question
Here are the parts of the code:
I have got no clue on how or what goes where?

The upload form with the HTML code:
PHP Code:
echo "<pre>";
print_r($_FILES);
echo "</pre>";

$target_path = "C:/Documents and Settings/Jay/My Documents/sites/jtechsystems-php/upload/".$_FILES['uploadedfile']['name'];
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" />
<input name="uploader" type="submit" id="uploader" value="Upload File" />
<br />
<?php //echo $error; would like to use it but no idea how?>
</form>
</body>
</html>
The if then else parts: //which goes where?
PHP Code:
if ((($_FILES["uploadedfile"]["type"] == "image/gif"
|| (
$_FILES["uploadedfile"]["type"] == "image/jpeg"
|| (
$_FILES["uploadedfile"]["type"] == "image/pjpeg")) 
&& (
$_FILES["uploadedfile"]["size"] < 100000)) //set file size here
{
if (
$_FILES["uploadedfile"]["error"] > 0)
{
echo 
"Return Code: " $_FILES["uploadedfile"]["error"] . "<br />";
}else{
echo 
$_FILES["uploadedfile"]["name"] . " already exists. ";
}else{
//upload the file! (I think?)

I hope this makes sense, cause to me it don't.
Cheers
student101 is offline   Reply With Quote
Old 03-10-2008, 12:45 PM   #6
student101
 
Join Date: Dec 2007
Posts: 379
Default

Sh1t you posted just just before me,
hectic!
student101 is offline   Reply With Quote
Old 03-10-2008, 12:47 PM   #7
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

if you dont understand it then you are not learning

you need to understand every aspect as i wont finish any code so people can copy and paste. I let you complete my examples as its my way to teach. I never write solutions for anyone. If you are copying (parrot fashion) my tutorials then you wont benefit from them
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-10-2008, 01:02 PM   #8
student101
 
Join Date: Dec 2007
Posts: 379
Default

Quote:
Originally Posted by davidj View Post
if you dont understand it then you are not learning
you need to understand every aspect as i wont finish any code so people can copy and paste. I let you complete my examples as its my way to teach. I never write solutions for anyone. If you are copying (parrot fashion) my tutorials then you wont benefit from them
You've lost me?

Your video has file downloads, that's what I added along with the "if then else" code.
The problem I have is knowing where to place those if then else parts?

Cheers
student101 is offline   Reply With Quote
Old 03-10-2008, 01:06 PM   #9
student101
 
Join Date: Dec 2007
Posts: 379
Default

By the way,
those mime types is what I used for my forcing a file download, instead of opening the file and waisting bandwidth.
Funny, I never did save that bookmark, thanks for the link.
student101 is offline   Reply With Quote
Old 03-10-2008, 01:11 PM   #10
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

its good to collect some good links

tip: keep the links on a USB pen drive so you can access them anywhere.

ok

did my example become clear?
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:13 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com