www.webdeveloper.com
Page 4 of 23 FirstFirst ... 2345614 ... LastLast
Results 46 to 60 of 340

Thread: How to: Upload images using PHP

  1. #46
    Join Date
    May 2006
    Posts
    4

    Question Can this be incorporated?

    hello All,

    I'm a newbie.. er newby when it comes to php. sql etc.

    I am presently using a oscommerce shopping cart. I loaded a contribution called customer add product. I loaded it up and everything seems to work fine. All except for the images will not upload. I've attemted to make little changes here and there and have been searching for answers as to why,
    but nothing. The contribution does work for other people.. so I am so confussed at what to do right now. I don't know what is causing the problem or how to turn it around.

    The images are suposed to load in a shop/images/thumb folder with permision set on 777 I have that and it still doesnt work.

    Im wondering if I am missing something either in sql or my root folder which enables this. Am I suposed to have an upload_image.php like the one your describing here? I've completed a search in my folders and I don't seem to have one. atleast not by the same name. Could I load these files into the oscommerce cart? Would it make a differnce or crash it?

    MY head is so fried Im not even sure what I should be asking.
    Just any information about sql , php and image uploading might boot me in the proper direction.

    If anyone wanted to take a look at the site before I destroy it completly
    http://www.mycreativeworld.com/shopping
    Login test@test.com
    password 123456

    Nan

  2. #47
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    This tutorial is for people that want to allow their visitors to upload image to their webite. If you are uploading images to your own site you should use an FTP client.

  3. #48
    Join Date
    May 2006
    Posts
    4

    Red face

    Quote Originally Posted by bokeh
    This tutorial is for people that want to allow their visitors to upload image to their webite. If you are uploading images to your own site you should use an FTP client.
    Yup! thats exactly what I'm trying to enable. A mod/contribution that will allow customers to upload their own product images and descriptions.

    I put your upload.zip in my site and after changing the persmissions it worked.

    I gave a bad log in email in my last post. I've corrected it.

    http://www.mycreativeworld.com/shopping
    Login test@test.com
    Passw 123456

    If you log into the account you will see "Add New Product"
    This is where customers can add their own product images to the shopping cart. But I cant get the upload to work. Im not being shown an error other than "file does not exist" and Sql isnt really showing me any errors either. (only for an old cart)

    But yours did work so that must mean that it can be done and its not some sql security issue getting in the way... Yes / no?

    I just don't know where to look to make possible corrections.

    Nan

    PS. If my question/s are outside of what you would like discussed in this thread let me know and I can re ask it elsewhere. so it doesn't cunfuse people down the road or mess up a clean thread
    Last edited by starynightskyz; 05-10-2006 at 03:48 PM. Reason: Addon

  4. #49
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    I think you should start a new thread. Try to narrow things down to one section of code you think is faulty and post that along with your explanation.

  5. #50
    Join Date
    Feb 2005
    Posts
    345
    hi bokeh et al!

    i extended your fabulous script to an news upload script with optional image upload and a event script where one can upload a additional infosheet as pdf optionally.

    the only drawback is that when there is an error (like file too big or no event title given) the form gets reloaded and the user has to type in all the details again from scratch..

    is there a way to replace header("Refresh: 3; URL=\"$uploadForm\""); with a javascript go -1 since the browsers would then recall what was typed into the fields before?

    if so, how could this be implemented?

  6. #51
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by jogol
    is there a way to replace header("Refresh: 3; URL=\"$uploadForm\""); with a javascript go -1 since the browsers would then recall what was typed into the fields before?
    Without starting a Javascript versus PHP debate, doing this with Javascript is a bad thing since there is no redundancy if Javascript is disabled. Also browsers don't necessarily record all the data in the input fields when using history. The method the demo uses was used in this instance to so each step of the proceedure was clear defined and understandable. The easiest way to deal with your problem is to rewrite the error handler so that instead of redirecting back to the upload form it instead reloads the form with the data preloaded. (PHP solution).
    Last edited by bokeh; 05-12-2006 at 05:58 AM.

  7. #52
    Join Date
    Jul 2006
    Posts
    24
    Hi,

    I getting the error: "'receiving directory insuffiecient permission'"
    What should I do to fix it?

    Thanks,
    Laura

  8. #53
    Join Date
    Mar 2006
    Location
    Chennai
    Posts
    32
    Hi,
    Give the folder's permission 777 in FTP.
    Or entering into the cpanel->Files->www->Upload Folder--> Change the permission as 777.
    Then you can do it.
    $file__name="john.doc";
    move_uploaded_files($HTTP_POST_FILES(['file']['tmp_name']),'upoad_Files'.$filename);
    Do it like this way.

  9. #54
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by john_de116
    $HTTP_POST_FILES
    That is depracated. Use $_FILES

  10. #55
    Join Date
    Jul 2006
    Posts
    24
    Thanks both of you for your replies; however, I'm using dreamweaver MX to upload the files, and I cannot follow your steps. Would you please give me more details. Thanks.

    Bokeh thanks for this great script.

  11. #56
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    You need to use your FTP client (the program you use to uploaded your scripts) to select the directory that recieves the files and change it to 0777 permission.

  12. #57
    Join Date
    Jul 2006
    Posts
    24
    I ftp through the web address and allowd all persmissions for owner, groups, and users to he uploader folder; However, I'm still receiving the same error message. My guess is that I'm failing to giving permissions to the correct file/folder.
    Should I modify any part of the script?
    for example in the upload.processor.php file:
    // fieldname used within the file <input> of the HTML form
    $fieldname = 'file';

    => shouldn't instead of the name 'file', I have to create a folder to place the images that are going to be uploaded, and put the name there?

    Thanks for your help.

  13. #58
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by lapfama
    allowd all persmissions for owner, groups, and users to he uploader folder
    You need to set the permission of the receiving directory to 0777 not the uploaded folder.

  14. #59
    Join Date
    Jul 2006
    Posts
    24
    Got it, thanks
    Last edited by lapfama; 07-23-2006 at 01:17 PM.

  15. #60
    Join Date
    Jun 2006
    Posts
    159
    Quote Originally Posted by Sheldon
    well sorry i didnt really answer that very well, its been a long day

    If it were me and i havnt really looked at the code,
    but here
    PHP Code:

    // now let's move the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
        
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess); 
    I would add a mySQL insert script

    like this

    PHP Code:

    // now let's move the file to its final location and allocate the new filename to it
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
     
    //in addition to Bokeh's script you can insert each record into a database.

    $q "INSERT INTO table_name (`filename`,`date`) VALUES ('$uploadFilename',$date(dMy))"
    $s mysql_query($q);
    //if an error
    echo(mysql_error());

    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to a success page.
    header('Location: ' $uploadSuccess); 

    and to display it would be a simple select script
    I can't get this to work
    I'm sure i'm just doing something wrong, but i've tried everything...

    my script looks like this.

    PHP Code:
    // now let's move the file to its final and allocate it with the new filename
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or 
    error('receiving directory insuffiecient permission'$uploadForm);
    //in addition to Bokeh's script you can insert each record into a database.
    $conn mysql_connect("localhost","Munkeyman","hgfjde34583")
        or die(
    "Could not connect to MySQL");
      
    $db mysql_select_db("images",$conn)
        or die(
    "Could not select database");
    $q "INSERT INTO uploaded_images (`filename`,`date`) VALUES ('$uploadFilename',$date(dMy))";
    $s mysql_query($q$conn);
        
    //if an error
    echo(mysql_error());
        
    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to the success page.
    header('Location: ' $uploadSuccess); 
    and i'm getting this error

    Unknown column 'dMy' in 'field list'
    Warning: Cannot add header information - headers already sent by (output started at c:\Apache\htdocs\Dinamic uni\uploader\new.upload.processor.php:69) in c:\Apache\htdocs\Dinamic uni\uploader\new.upload.processor.php on line 73

    my database looks like this..

    Code:
    mysql> use images;
    Database changed
    mysql> show tables;
    +------------------+
    | Tables_in_images |
    +------------------+
    | uploaded_images  |
    +------------------+
    1 row in set (0.00 sec)
    
    mysql> explain uploaded_images;
    +----------+-------------+------+-----+---------+-------+
    | Field    | Type        | Null | Key | Default | Extra |
    +----------+-------------+------+-----+---------+-------+
    | id       | int(11)     | YES  |     | NULL    |       |
    | filename | varchar(50) | YES  |     | NULL    |       |
    | date     | varchar(50) | YES  |     | NULL    |       |
    +----------+-------------+------+-----+---------+-------+
    3 rows in set (0.00 sec)
    
    mysql>
    If any one can help me it would be much appreciated!

Thread Information

Users Browsing this Thread

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

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