Results 1 to 4 of 4

Thread: Form to upload my file that renames

  1. #1
    Join Date
    Aug 2009
    Posts
    56

    Form to upload my file that renames

    I created a form that renames the file uploaded with the date. The thing is I am careful that the file name remains as it is, but I am blocked also confused. And I would add 6 additional upload and I see no solution.

    PHP Code:
    $datedate("ymdhis" );
    $promotion = (!empty($_POST['promotion'])) ? addslashes($_POST['promotion']) : '';
    $ordrepromo = (!empty($_POST['ordrepromo'])) ? addslashes($_POST['ordrepromo']) : '';
    $news= (!empty($_POST['news'])) ? addslashes($_POST['news']) : '';
    $ordrenew = (!empty($_POST['ordrenew'])) ? addslashes($_POST['ordrenew']) : '';
    $category = (!empty($_POST['category'])) ? addslashes($_POST['category']) : '';
    $subTopics = (!empty($_POST['subTopics'])) ? addslashes($_POST['subTopics']) : '';
    $mark = (!empty($_POST['mark'])) ? addslashes($_POST['mark']) : '';
    $namecuisine = (!empty($_POST['namecuisine'])) ? addslashes($_POST['namecuisine']) : '';
    $built = (!empty($_POST['built'])) ? addslashes($_POST['built']) : '';
    $posable = (!empty($_POST['posable'])) ? addslashes($_POST['posable']) : '';
    $name = (!empty($_POST['name'])) ? addslashes($_POST['name']) : '';
    $reference = (!empty($_POST['reference'])) ? addslashes($_POST['reference']) : '';
    $description = (!empty($_POST['description'])) ? addslashes($_POST['description']) : '';
    $note = (!empty($_POST['note'])) ? addslashes($_POST['note']) : '';
    $view = (!empty($_POST['view'])) ? addslashes($_POST['view']) : '';
    $guarantee = (!empty($_POST['guarantee'])) ? addslashes($_POST['guarantee']) : '';
    $label = (!empty($_POST['label'])) ? addslashes($_POST['label']) : '';
    $consumption = (!empty($_POST['consumption'])) ? addslashes($_POST['consumption']) : '';
    $dimension = (!empty($_POST['dimension'])) ? addslashes($_POST['dimension']) : '';
    $color = (!empty($_POST['color'])) ? addslashes($_POST['color']) : '';
    $price = (!empty($_POST['price'])) ? addslashes($_POST['price']) : '';
    $promo = (!empty($_POST['promo'])) ? addslashes($_POST['promo']) : '';
    $aFile = (!empty($_POST['aFile'])) ? addslashes($_POST['aFile']) : '';
    // 
    if (is_uploaded_file($_FILES['aFile']['tmp_name'])){
        echo 
    "<b>Name of the file on the server :<b> " $_FILES['aFile']['tmp_name'] . "<br>";
        echo 
    "<b>Filesize :<b>" $_FILES['aFile']['size'] . "<br>";
        echo 
    "<b>Type of file :<b>" $_FILES['aFile']['type'] . "<br>";
        
    copy($_FILES['aFile']['tmp_name'],"./upload/${date}-immo.jpg" );
        
    $query "INSERT INTO products (date,promotion, ordrepromo, news, ordrenews, category, subTopics, mark, namecuisine, built, posable, name, reference, description, note, view, guarantee, label, consumption, dimension, color, price, promo, aFile)  VALUES(NOW(),'$promotion','$ordrepromo','$news','$ordrenew','$category','$subTopics','$marque','$namecuisine','$built','$posable','$name','$reference','$description','$note','$view','$guarantee','$label','$consumption','$dimension','$color','$price','$promo', '${date}-immo.jpg' )";
    }
    else{
        
    $query "INSERT INTO produits (date,promotion, ordrepromo, news, ordrenew, category, subTopics, mark, namecuisine, built, posable, name, reference, description, note, opinion, guarantee, label, consumption, dimension, color, price, promo, aFile)
    VALUES(NOW(),'
    $promotion','$ordrepromo','$news','$ordrenew','$category','$subTopics','$marque','$namecuisine','$built','$posable','$name','$reference','$description','$note','$view','$guarantee','$label','$consumption','$dimension','$color','$price','$promo', '' )";
    echo 
    "No file uploaded !?";
    }
    $res mysql_query($query) or die(mysql_error());
    echo 
    'Your data is saved.';
    mysql_close();
    ?> 

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Form to upload my file that renames

    I think it's your line
    PHP Code:
    copy ($ _FILES 'aFile'] [ 'tmp_name'],"./ upload / $ (date)-immo.jpg "); 
    who is involved. By that, it should be renamed:
    PHP Code:
    copy($_FILES['aFile']['tmp_name'],"./upload/".$_FILES['aFile']['name']); 
    To add others is simple, you add fields to type "file", giving them a different name (HTML attribute name)

    Then in your $ _FILES array you have multiple lines.
    $ _FILES [ 'File1'];
    $ _FILES [ 'File2'] / / etc. ...

    You can of course do a foreach on your $ _FILES array.

  3. #3
    Join Date
    Aug 2009
    Posts
    56

    Re: Form to upload my file that renames

    I have a syntax error. I tried
    PHP Code:
    '$ _FILES [' AFile '] [' name ']'"; 
    but like, the more it goes, the less I understand.

    And if I leave my old insert, the file happens to him as he is with his real name, so it's great already

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Form to upload my file that renames

    Excuse me, little oversight.

    PHP Code:
    $query "INSERT INTO products (date,promotion, ordrepromo, news, ordrenew, category, subTopics, mark, namecuisine, built, posable, name, reference, description, note, view, guarantee, label, consumption, dimension, color, price, promo, aFile)
    VALUES(NOW(),'
    $promotion','$ordrepromo','$news','$ordrenew','$category', '$subTopics','$marque','$namecuisine','$built','$posable','$name', '$reference','$description','$note','$view','$guarantee','$label', '$consumption','$dimension','$color','$price','$promo', '{$_FILES['aFile']['name']}' )"
    At worst, if it does not work (although there is no reason!):

    PHP Code:
    $query "INSERT INTO products (date,promotion, ordrepromo, news, ordrenew, category, subTopics, mark, namecuisine, built, posable, name, reference, description, note, view, guarantee, label, consumption, dimension, color, price, promo, aFile)
    VALUES(NOW(),'
    $promotion','$ordrepromo','$news','$ordrenew','$category', '$subTopics','$marque','$namecuisine','$built','$posable','$name', '$reference','$description','$note','$view','$guarantee','$label', '$consumption','$dimension','$color','$price','$promo', '".$_FILES['aFile']['name']."' )"

Similar Threads

  1. How to upload a file with an email?
    By Unnati! in forum Technology & Internet
    Replies: 4
    Last Post: 18-06-2011, 09:27 PM
  2. Need method of JSP File Upload
    By Abigail101 in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 02:37 AM
  3. How to create an Upload-File Form in PHP?
    By Leoniee in forum Software Development
    Replies: 4
    Last Post: 21-02-2010, 07:31 AM
  4. Css File Upload
    By Zidaan in forum Software Development
    Replies: 2
    Last Post: 09-03-2009, 10:59 PM
  5. Upload a file to MediaFire
    By MATSU in forum Tips & Tweaks
    Replies: 1
    Last Post: 23-02-2009, 12:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,989,971.93677 seconds with 16 queries