FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 22nd, 2003, 06:05 AM
ourweehome ourweehome is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 40 ourweehome User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 50 m 7 sec
Reputation Power: 6
ftp upload file then store filename in mysql

Hi all, I wonder if anyone could give me a hand with this?..
I am building an online catalogue for a shop. There is an admin section where the administrator can add new products. When adding products, a thumbnail and a full size image are uploaded into a directory, and the uploaded files are referenced in mysql.
Hope that makes sense?

This is the code I have to do this job:
PHP Code:
<?php include("../Connections/colourConn.php"); ?>
<?php
    mysql_select_db
($database_colourConn$colourConn);
    
$newName $_POST["name"];
    
$newDesc $_POST["desc"];
    
$newPrice $_POST["price"];
    
$newSection $_POST["section"];
    
$thumb $_POST["thumbnail"];
    
$full $_POST["fullsize"];
    
$dir "/docs/shop/shopImages/";
    
    function 
connect(){
        
$conn ftp_connect("***SERVERNAME***");
        
ftp_login($conn"***USERNAME***""***PASSWORD***");
        return 
$conn;
    }
    
$result connect();
    
ftp_chdir($result$dir);
    
$thumb_code ftp_put($result$thumb$thumbFTP_BINARY);
    
$full_code ftp_put($result$full$fullFTP_BINARY);
    
ftp_quit($result);    
    
    
mysql_query("insert into `products` ( `productName`,`cat_id`,`productDesc`,`productPrice`,`smallPic`,`largePic` ) VALUES ( '".$newName."','".$newSection."','".$newDesc."','".$newPrice."','".$thumb_name."','".$full_name."')");
    
header("location: view.php");
?>


I get the variables from a multipart/form-data form. I know that my host supports php ftp as I have used other scripts on it before.

But it doesn't work! I have tried everything I can think of, but it doesn't upload the files or reference them in mySQL(store the filename).

Please can anybody help me?
I will be eternally grateful!

Thanks!

Reply With Quote
  #2  
Old July 22nd, 2003, 08:19 AM
pmm pmm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2002
Posts: 679 pmm User rank is Sergeant (500 - 2000 Reputation Level)pmm User rank is Sergeant (500 - 2000 Reputation Level)pmm User rank is Sergeant (500 - 2000 Reputation Level)pmm User rank is Sergeant (500 - 2000 Reputation Level)pmm User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 3 h 38 m 45 sec
Reputation Power: 12
This isn't the way to do it - have a search for file upload or look in the manual. I can't understand what you are sending in your post vars, but I can't see it working like this.

It's more usual to use HTTP for the file upload, rather than ftp, to do this you have enctype = "multipart/form-data" as you have, but for the images you should use an input type="file". This will give you a browse button, allowing the user to select a local file for upload. Maybe you have done this. Then you access this using $_FILES - if your form field is called "userfile", you have $_FILES['userfile']['tmp_name'] and so on. You should perform some checks on the file being uploaded, and use move_uploaded_file() to save it to a permanent location.

This is just an outline, you should be able to find more detail in the manual or this forum.

Reply With Quote
  #3  
Old July 22nd, 2003, 08:41 AM
Sotonin Sotonin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 448 Sotonin User rank is Private First Class (20 - 50 Reputation Level)Sotonin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 25 m 25 sec
Reputation Power: 6
something sort of like this, you'll have to modify it to create your directories and such. this script just uploads up to 10 images changable by modifying numoffile variable.

PHP Code:
 $file_dir  "/home/path/to/your/files/" $image_dir "/";
$numoffile 10;
    
    if (
$_POST) {
        for (
$i=0;$i<$numoffile;$i++) {
          if (
trim($_FILES['myfiles']['name'][$i])!="") {
            
$newfile $file_dir.$_FILES['myfiles']['name'][$i];
            
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $file_dir $image_dir "_" $filenum ".jpg");
            
chmod($file_dir $image_dir "_" $filenum ".jpg"0777);
            
$filenum = ($filenum 1);
            
$j++;
          }
        }
        
        if (isset(
$j)&&$j>0) {
            echo 
"successful";
            exit();
        }
    } else {
        print 
"Uploading images to:<br />";
        print 
$file_dir "<br />";

        print 
"<form method='post' enctype='multipart/form-data'>"
            for(
$i=0;$i<$numoffile;$i++) { 
                print 
"<input type='file' name='myfiles[]' size='30'><br>"
            }
        print 
"<input type='submit' name='action' value='Upload'>"
        print 
"</form>"
    } 
__________________
-Sotonin

Reply With Quote
  #4  
Old July 22nd, 2003, 09:33 AM
k89mmk k89mmk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Newfoundland, Canada
Posts: 97 k89mmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 15 sec
Reputation Power: 6
Why doesn't this work for me???

I've tried to figure out how to upload files before, but it never seems to work. So after looking at your post, I figured I'd give it a go - but still no !!!

It seems to be working - I click upload, it thinks about it, then reloads the page. I even put in an error check with move_uploaded_files, and there were no errors.

But the file never appears!!!! Why oh why?

Reply With Quote
  #5  
Old July 22nd, 2003, 09:46 AM
Sotonin Sotonin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 448 Sotonin User rank is Private First Class (20 - 50 Reputation Level)Sotonin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 25 m 25 sec
Reputation Power: 6
My code will only work with jpg files.... so that may be part of the problem what are you uploading?

Reply With Quote
  #6  
Old July 22nd, 2003, 09:52 AM
k89mmk k89mmk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Newfoundland, Canada
Posts: 97 k89mmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 15 sec
Reputation Power: 6
nope

I was actually trying to upload a .png, just as a test. I converted it to .jpg, then .jpeg, but neither worked. Is it possible that the permissions don't allow this? I'm using a professional server ... maybe they don't want to allow uploading. Is there a way to tell if this is the cause?

Reply With Quote
  #7  
Old July 22nd, 2003, 10:04 AM
Sotonin Sotonin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 448 Sotonin User rank is Private First Class (20 - 50 Reputation Level)Sotonin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 25 m 25 sec
Reputation Power: 6
you have to chmod whatever directory you are tyring to upload to to 777. well prolly only 775 but try 777 just to be sure. As far as server settings im not sure to be honest.

Reply With Quote
  #8  
Old July 23rd, 2003, 09:24 AM
k89mmk k89mmk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Newfoundland, Canada
Posts: 97 k89mmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 15 sec
Reputation Power: 6
Is there a way to set the chmod settings with Dreamweaver, or another windows program? I've yet to find a way ...

Reply With Quote
  #9  
Old July 23rd, 2003, 09:26 AM
k89mmk k89mmk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Newfoundland, Canada
Posts: 97 k89mmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 15 sec
Reputation Power: 6
Is there a way to set the chmod settings with Dreamweaver, or another windows program? I've yet to find a way ...

Reply With Quote
  #10  
Old July 23rd, 2003, 09:26 AM
k89mmk k89mmk is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Newfoundland, Canada
Posts: 97 k89mmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 23 m 15 sec
Reputation Power: 6
Is there a way to set the chmod settings with Dreamweaver, or another windows program? I've yet to find a way ...

Reply With Quote
  #11  
Old July 23rd, 2003, 09:36 AM
Sotonin Sotonin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 448 Sotonin User rank is Private First Class (20 - 50 Reputation Level)Sotonin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 25 m 25 sec
Reputation Power: 6
nope. just download a free trial of cuteftp or ftp voyager from download.com

Reply With Quote
  #12  
Old July 23rd, 2003, 09:37 AM
Sotonin Sotonin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 448 Sotonin User rank is Private First Class (20 - 50 Reputation Level)Sotonin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 12 h 25 m 25 sec
Reputation Power: 6
nope. just download a free trial of cuteftp or ftp voyager from download.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > ftp upload file then store filename in mysql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |