www.webdeveloper.com
Page 14 of 23 FirstFirst ... 41213141516 ... LastLast
Results 196 to 210 of 340

Thread: How to: Upload images using PHP

  1. #196
    Join Date
    Mar 2005
    Posts
    140
    I think I've solved my problem - I don't store the whole pathway to the file in the db, hope the script works fine once it is online...
    I think it should be also noted in the original tutorial that this scripts works basically for ANY type of files, not only for images.

  2. #197
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by Louigi Verona
    the original tutorial that this scripts works basically for ANY type of files, not only for images.
    Only if modified since the script test to see if the file is an image.

  3. #198
    Join Date
    Mar 2005
    Posts
    140
    And how do you test file types anyway? For example if it's mp3 - also a popular file upload.

  4. #199
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

  5. #200
    Join Date
    May 2008
    Posts
    5
    What the hell is a receiving directory??

    I keep getting that insufficient permission error.

  6. #201
    Join Date
    Mar 2005
    Posts
    140
    Quote Originally Posted by bokeh
    Read up on the mp3 format and then write a script to check the file structure matches that format.
    Yeah, actually I've been making certain read ups for quite some time now, but no luck so far. Though I did find classes to work with that but as I do have the upload code written by you and slightly modified by myself for my needs, I just want to incorporate the check into it and that's all.

    Afaik, checking for mime-type is not good for security, right?
    Last edited by Louigi Verona; 05-28-2008 at 08:54 AM.

  7. #202
    Join Date
    Mar 2005
    Posts
    140
    Quote Originally Posted by Vanterion
    What the hell is a receiving directory??

    I keep getting that insufficient permission error.
    Receiving dir is the one into which you upload your files. If it's permissions are set to read only, you can not write files into it.

  8. #203
    Join Date
    Jun 2008
    Posts
    1
    Just wanted to say a BIG ty to Bokeh. Someone wanted a place for people to submit their fan art and I set up the free Form M@iler script (which emails the file to you) which I realized left my hosts server COMPLETELY VULNERABLE to any type of upload.
    I managed to patch in Bokeh's script by putting it in front of the form M@ailer script.
    All I had to figure out was to put if ($_FILES[$fieldname]['tmp_name'] != '' ) { in front of the file check variables, and } at the end, then comment out the file storage commands so it went to the Form M@iler script instead

    took me ages but it was big fun
    THANK YOU SO MUCH!!!

    -MrEd: )

  9. #204
    Join Date
    Jun 2008
    Posts
    2
    Hey all, I've cut and pasted all week to get the code to what I wanted, and I got it to work perfectly on my localhost, but when moving everything to public server I immediately bumped into problems.

    I want to make a new directory for each posting, and I do that like this:



    // Create new dir in img directory for each post
    $dirname = date("iBs", time());
    umask(0);
    mkdir("img/$dirname", 0777);
    chmod("img/$dirname", 0777);

    // Make a note of the current working directory, relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

    // Make a note of the directory that will recieve the uploaded files.
    $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'img/$dirname/';



    And I thought I could simply add $dirname/ to the $uploadsDirectory, but then I get the "receiving directory insuffiecient permission" warning further down in the code, so it's obviously not that easy.

    If I don't add $dirname/ everything works alright - the file transfer to the img folder - so I guess the $dirname/ is my issue... Do I have to chmod() that in some smart way as well, or?

    The '$dirname'-directory is created as it should 0777, sub-img...

    /staff
    Last edited by staffstaff; 06-20-2008 at 02:01 PM.

  10. #205
    Join Date
    Jun 2008
    Posts
    2

    Maybe solved...

    aaaahhh, it's an UID /GID problem... need to configure php.ini as I read somewhere.

    Thank you to myself.

  11. #206
    Join Date
    Jul 2008
    Posts
    1
    I have problems with uploading images! I am not too new to PHP I just don't have any knowledge of file handling with PHP.

    I want user to input the paths to the images and id of a game (this is for a game database). And when user selects upload this script would create a directory (name would be an id that user entered) and inside that folder there are normal images and anoder directory with thumbnails (named thumbs).

    Here is the fun part! When a user selects game with that id script checks if there is a folder with that ID and then displays all that thumbnails with links to a full image. And images should be named like id_01,id_02,id_03....

    How can I do something like that?

  12. #207
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    Hi all this script isd great thanks very much Bokeh. Unfortunately every now and then my client is experiencing problems with uploading an image and the latest one was the following:

    PHP Code:
    Fatal errorCall to undefined function: error() in
    C
    :\Inetpub\vhosts\xxxx.com\xxxx\xxxx\xxxx\xxxx.php on line 56 
    which is the following few lines of code

    PHP Code:
    foreach($active_keys as $key

        (
    $_FILES[$fieldname]['error'][$key] == 0
            or 
    error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm); 

    Can I just add that when Ive gone back into this and tried to upload the script the image is uploaded correctly. However the image is 1.8MB and is over 4000px wide and the client themselves admit that their internet line is not the strongest. Ive spoken to my server company and their maximum upload is 2MB so its not that!

    What Im wondering is the script timing out to give me this error or is there an error in the script that I am blind too?

    Any advice much appreciated!!

  13. #208
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739

  14. #209
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    A while ago I asked you for a piece of script which ifd there was no image uploaded then the script would just exit i.e. this script also uploads an article and an article not always has an image hence we must exit the script. I think whats happening is that the script has timed out whist at this point in the script and hence when it gets to this point it looks like there is no image!! Does that make sense? As I say this isnt happening all the time only at certain points.

    Regards

    Mike

  15. #210
    Join Date
    Mar 2006
    Location
    Liverpool, UK
    Posts
    278
    Hi this is the script in regard to the error above. Now when I enter an image that is 4841 * 2102 Im getting the error mentioned above. However when I reduce the image to 2420 * 1050 the script runs fine. Now what Im wondering is there annything that I need to do to my ini file in regard to accept this type of image or would it be best to edit my file to make it less memory heavy! Any advice is greatly appreciated. I will have to send it in two parts unfortunately.

    PHP Code:
    <?php

    @ini_set("memory_limit""64M");


    $title=$_REQUEST['title'];
    $aliases=$_REQUEST['aliases'];
    $catID=$_REQUEST['category'];
    $author=$_REQUEST['author'];
    $createddate=$_REQUEST['createddate'];
    $publishingdate=$_REQUEST['publishingdate'];
    $description=$_REQUEST['description'];
    $keywords=$_REQUEST['keywords'];
    $scrollbar=$_REQUEST['scrollbar'];
    $snippet=$_REQUEST['snippet'];
    $frontpage=$_REQUEST['frontpage'];
    $articlekw=$_REQUEST['article'];
    $article=mysql_real_escape_string($_REQUEST['article']);
    $display=$_REQUEST['display'];
    $email=$_REQUEST['email'];

    if (
    $keywords=="") {
     
    $words=$title "," $articlekw;
     
    $words=strtolower($words);
     
    $p=". , : ; ' ? ! ( ) \" \\";
     
    $p=explode(" "$p);
     
     foreach(
    $p as $val){
            
    $words=str_replace($val," "$words);
        }
     
     
    $commonwords="about,that's,this,that,than,then,them,there,their,they,it's,with,which,were,where,whose,when,what,her's,he's,have,like,the";
     
    $commonwords=explode(","$commonwords);
     
    $words=explode(" "$words);
     
     foreach (
    $words as $val) {
      
    $common=false;
      if (
    strlen($val)>3) {
       foreach (
    $commonwords as $comval) {
        if (
    $comval==$val) {
         
    $common=true;
        }
       }
       if (
    $common!=true) {
        
    $keywords[]=$val;
       }
      }
     }
     
     
    $keywords=array_count_values($keywords);
     
    arsort($keywords);
        foreach (
    $keywords as $key => $value) {
            
    $keywordlist .= $key ", ";
        }
     if (
    substr($keywordsstrlen($keywords), 1)==",") {
      
    $keywordlist=substr($keywords0, (strlen($keywords)-1));
     } 
     
    $keywords=$keywordlist;
     
    $keywords=str_replace("\n"" "$keywords);
    }

    if (
    $description=="") {
     
    $description=$snippet;
    }
     
    $sql="INSERT INTO article (title, aliases, author, createddate, publishingdate, description, keywords, article, catID, snippet, frontpage, scrollbar, email, display) VALUES ('$title', '$aliases', '$author', '$createddate', '$publishingdate', '$description', '$keywords', '$article', '$catID', '$snippet', '$frontpage', '$scrollbar', '$email', '$display')";
    $result=mysql_query($sql) or die ("Error!! BAD INSERT STATEMENT1!");

    $query="Select Max(articleID) AS articleID from article";
    $result=mysql_query($query) or die ("ERROR!! Unable to perform query!");
    $row=mysql_fetch_array($result);
    extract($row);

    $sql10="INSERT INTO article3 (articleID, title, aliases, author, createddate, publishingdate, description, keywords, article, catID, snippet, frontpage, scrollbar, email, display) VALUES ('$articleID', '$title', '$aliases', '$author', '$createddate', '$publishingdate', '$description', '$keywords', '$article', '$catID', '$snippet', '$frontpage', '$scrollbar', '$email', '$display')";
    $result10=mysql_query($sql10) or die ("Error!! BAD INSERT STATEMENT2!");
    The above part adds the article to the database. and the next post uploads the image
    Last edited by cs3mw; 07-23-2008 at 07:00 AM.

Thread Information

Users Browsing this Thread

There are currently 6 users browsing this thread. (1 members and 5 guests)

  1. OldBoy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles