SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question file upload problem in mysql

    hi

    i am uploading a file into my server and storing path in my mysql db.
    i am getting the correct path before inserting that path into the database
    for eg:
    i am getting the path as c:\wamp\www\images\hotels\

    but when i am inserting this path into the database i am getting the path as
    c:wampwwwimageshotels

    this is the way the path stored in my mysql db.

    how can i solve this. please help me

    Thanks to all

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When validating the input, do you do stripslashes?

  3. #3
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post us the entire validation code?

  5. #5
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     echo $up=fileupload();

      function 
    fileupload()
          {
            
                     
    $ext findexts($_FILES['uploaded_file']['name']);
                     
    $random_digit=uniqid(rand(0000,9999));
                     
                     
    $newname dirname(__FILE__)."\images\hotel\\".$random_digit.".".$ext;  
                     
                     if ((
    $ext == "jpg") || ($ext == "jpeg") || ($ext == "gif") || ($_FILES["uploaded_file"]["type"] == "image/jpeg") || ($_FILES["uploaded_file"]["type"] == "image/gif"))
                         {
                              if(
    move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newname))
                               {
                              echo 
    "file uploaded";
                               }
                               else{
                                echo 
    "Sorry, there was a problem uploading your file.";
                                      }
                          }
                     else 
                          {
                               echo 
    'files should be jpeg or gif'
                          }
                        return  
    $newname;
          }

     function 
    findexts($filename)

            {
                        
    $filename strtolower($filename) ;
                        
    $exts split("[/\\.]"$filename) ;
                        
    $n count($exts)-1;
                        
    $exts $exts[$n];
                        return 
    $exts;
            } 

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    Code:
    $newname = dirname(__FILE__)."/images/hotel/".$random_digit.".".$ext;
    \ usually has to be escaped, so using / might solve it without escaping.

  7. #7
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But dirname(__FILE__)

    gives me

    c:\wamp\www\

  8. #8
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That does not matter if it returns c:\wamp\www\ after all you can concatenate with backslash /. it will work.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  9. #9
    SitePoint Zealot malluwood's Avatar
    Join Date
    Nov 2006
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but in dtabase now the path is storing as
    c:\wamp\www\images/hotels/

    so i am not geeting image when i put in my web page

  10. #10
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh that means you are storing full path in the database? Why do you need to store whole path to be stored in the database? Are you storing uploaded files in different paths something like dynamically creating the directories/folders? Otherwise if you are storing the uploaded files in a single directory, you just store the file name in the database. Save your path in some configuration file and use the path variable when you want to uploaded or output your file.

    Otherwise if you are compelled to use such then you can replace the \ with / with str_replace() function.

    PHP Code:
    $path "c:\wamp\www\images/hotels/";
    $path str_replace("\\""/"$path); 
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •