Current location: Hot Scripts Forums » Programming Languages » PHP » If statement in file upload


If statement in file upload

Reply
  #1 (permalink)  
Old 04-11-04, 10:02 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
If statement in file upload

Hi. I saw a post for a script request for an address book with photos, and figured I'd give it a shot at making one. I have come across one little glitch...

The form lets me add all the info and upload a photo with no problem. However, if I don't upload a photo, I want a default picture put in its place ( one that is already in the programs "photos" folder ). The db table has a field that holds the photos name, and the display page just links to the folder and the pic.

So basically, if there is no photo uploaded, I want the data "smile.gif" inserted into the field for the photo name. I've tried several if, and elseif, statements, to no avail. Any suggestions?

PHP Code:

    $first_name=$_POST['first_name'];
    
$last_name=$_POST['last_name'];
    
$home_phone=$_POST['home_phone'];
    
$cell_phone=$_POST['cell_phone'];
    
$work_phone=$_POST['work_phone'];
    
$address=$_POST['address'];
                
    
$filesize $_FILES['upfile']['size'];
    
$filetype $_FILES['upfile']['type'];
    
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "/Picodex/photos/"
        if (
move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_dir $_FILES['upfile']['name']))    { 
      
$filename $_FILES['upfile']['name'];   
                              
include(
"connect.php");
$conn mysql_connect("localhost","$dbuser","$dbpass");
if (!
$conn) die ("Could not connect MySQL");
mysql_select_db($dbname,$conn) or die ("Could not open database");
$query "INSERT INTO addresses 
VALUES('','
$first_name','$last_name','$home_phone','$cell_phone','$work_phone','$address','$filename')";
 
$result=mysql_query($query);
                
  echo 
"Your new contact has been added";
   } 
This is just giving me a blank page when I don't upload a file ( probably because there is no $filename for the insert ? ), but works fine when I do upload one. I took the if statements out that I had been trying, since they weren't working, and plan to add filetype and size limits in the future.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-11-04, 10:33 PM
Mister B.'s Avatar
Mister B. Mister B. is offline
Wannabe Coder
 
Join Date: Jul 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
why not try
PHP Code:

if ($_FILES['upfile']['name'] == ""){

// input smile.jpg in its place
} else {
//input that pic

just a thought
__________________
God save us from the religious fanatics
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-11-04, 10:54 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Still doesn't work. I also tried...

if (!$_FILES['upfile']['name']){
$filename="smile.gif";
}

No luck.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-12-04, 07:54 AM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
if (!is_uploaded_file($_FILES['upfile']['tmp_name'])) {

try that
__________________
New beta project: GFX-PRO.ATH.CX
Description: GFX-PRO a great new project that anyone can and setup in less then a minute. [ More info ]
Website: http://gfx-pro.ath.cx
Status: Online
http://gfx-pro.ath.cx/sig.png
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-12-04, 06:33 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Nope...just a blank page after submitting and no insertion to the db.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting and passing the file name during upload Bonzo PHP 11 03-28-04 09:06 AM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 10:54 PM
File Upload Script - Restricting file types ... Seldimi PHP 2 12-27-03 10:49 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM


All times are GMT -5. The time now is 12:46 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.