www.webdeveloper.com
Page 2 of 23 FirstFirst 123412 ... LastLast
Results 16 to 30 of 340

Thread: How to: Upload images using PHP

  1. #16
    Join Date
    Mar 2006
    Location
    Chennai
    Posts
    32
    Create a folder in Web space. Browse the images using <input type="file" name="photo"> Post to another page.
    if ($HTTP_POST_FILES['photo1']['name'] != "")
    {
    $Pict1=$Email.'_'.$random.'_1.jpg';
    copy($HTTP_POST_FILES['photo1']['tmp_name'],"Image_upload_Folder/".$Pict1);
    }
    I upload the images using this technique. Try this.
    By
    John Diraviyam,
    PHP Developer.

  2. #17
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by john_de116
    Create a folder in Web space. Browse the images using <input type="file" name="photo"> Post to another page.
    if ($HTTP_POST_FILES['photo1']['name'] != "")
    {
    $Pict1=$Email.'_'.$random.'_1.jpg';
    copy($HTTP_POST_FILES['photo1']['tmp_name'],"Image_upload_Folder/".$Pict1);
    }
    I upload the images using this technique. Try this.
    Use of $HTTP_POST_FILES is deprated and also disable on many servers with modern PHP builds.

  3. #18
    Join Date
    Sep 2005
    Posts
    1,633

    Error

    I have tested script and have the following question:
    The requested URL ...upload.processor.php was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    Do you know what can be wrong? Need help.
    I have created directory on web site: uploaded_files
    and code for path is:
    $uploadForm = 'http://www.my domain/' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

    Is this correct? Please help.

  4. #19
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    long time no see toplisek!

  5. #20
    Join Date
    Sep 2005
    Posts
    1,633
    Hi,
    yes a long time. I had many work to do.Now I will post some messages again. Can you help me with this?

  6. #21
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    Quote Originally Posted by toplisek
    and code for path is:
    $uploadForm = 'http://www.my domain/' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

    Is this correct? Please help.
    incorrect.

    HTTP_HOST will be somthing like "domain.com"
    For it to be a valid absolute url, bokeh added "http://"
    simply leave it to what it was

    I didn't watch the whole script, but i believe he would have written a comment if you had something to change.

  7. #22
    Join Date
    Sep 2005
    Posts
    1,633
    I have put:
    // make a note of the location of the upload form in case we need it
    $uploadForm = 'http://' . $_SERVER['mydomain.com'] . $directory_self . 'upload.form.php';
    It gives me error:
    Not Found
    The requested URL /www.mydomain.com/upload.processor.php was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  8. #23
    Join Date
    Jun 2004
    Location
    4846′36″ N 910′48″ E
    Posts
    3,747
    PHP Code:
    // make a note of the location of the upload form in case we need it
    $uploadForm 'http://www.my domain/' $_SERVER['HTTP_HOST'] . $directory_self 'upload.form.php'
    leave it to what it is

    Toplisek, sprichst du deutsch?

  9. #24
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    Quote Originally Posted by toplisek
    $uploadForm = 'http://www.my domain/' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

    Is this correct? Please help.
    LCF is right. That won't work. All you needed to do was download the zip and then upload it all to your server maintaining the directory structure in the zip file and it will work with any modifications.
    Last edited by bokeh; 03-10-2006 at 12:44 PM.

  10. #25
    Join Date
    Sep 2005
    Posts
    1,633
    Thanks Bokeh,
    it works. I have just two questions:
    1. I have given permission 777 (highest) and also first 0644
    but there is error:
    An error has occured: receiving directory insuffiecient permission... The upload form is reloading
    2. It was error that file is too large.
    I have changed to $max_file_size = 5000000; // size in bytes but it gives me error even file is 54 kB

    Need help

    to LiLcRaZyFuZzY:Ja, Ich kann deutsch sprechen.

  11. #26
    Join Date
    Jun 2005
    Posts
    17
    Im using the following to upload a single file. If the file is to large it won't uploaded - however - my error messages don't seem to be working.

    Anyone have any ideas?

    HTML Code:
    <script language=javascript>
    extArray = new Array(".jpg", ".jpeg",".gif");  //".png", , ".gif"
    function callSave()
    {
        if(!isCurrency(document.frmlisting.txtlistingprice.value)){
            alert("Price: Incorrect data");
            document.frmlisting.txtlistingprice.select();
    		return;
        }
    	if(isBlank(document.frmlisting.txtlistingtitle.value)){
        	alert("Title is Required");
            document.frmlisting.txtlistingtitle.focus();
        	return;
        }
    	if(!isBlank(document.frmlisting.txtlistingimage.value)){
    	    if(!isValidFile(document.frmlisting.txtlistingimage.value)){
    	        alert("Selected file is not a vaild image type. \nPlease select "+ (extArray.join("  ").toUpperCase())+ " files. ");
    	        document.frmlisting.txtlistingimage.select();
    	        return;
    	    }
        }
    	if(isBlank(document.frmlisting.txtlistingemail.value)){
            alert("Email is Required");
            document.frmlisting.txtlistingemail.select();
    		return;
    
        }
        if(!isEmail(document.frmlisting.txtlistingemail.value)){
            alert("Email: Incorrect data");
            document.frmlisting.txtlistingemail.select();
            return;
        }
    
    	document.frmlisting.action="listingsubmit.php";
        document.frmlisting.submit();
    }
    </script>
    <FORM name="frmlisting" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="500000">
    <Input type="file" name="txtlistingimage" style="WIDTH: 275px; HEIGHT: 20px" size="39" maxlength="100">
    <input type="button" class="btn_text" value="Preview" onclick="javascript:callSave();" style="border:solid-1px; color: #333333 ">
    The processor "listingsubmit.php"

    PHP Code:
    include("connection.php");
    $c_id $HTTP_POST_VARS['c_id'];
    $city  $HTTP_POST_VARS['cboCity'];
    $l_id $HTTP_POST_VARS['l_id'];
    $listing_title  $HTTP_POST_VARS['txtlistingtitle'];
    $listing_location  $HTTP_POST_VARS['txtlistinglocation'];

    if(isset(
    $HTTP_POST_VARS['txtlistingprice'])){
        
    $listing_price  $HTTP_POST_VARS['txtlistingprice'];
    }else{
        
    $listing_price =0;
    }
    $listing_text  $HTTP_POST_VARS['txtlistingtext'];
    $listing_address  $HTTP_POST_VARS['txtlistingaddress'];
    $listing_city  $HTTP_POST_VARS['txtlistingcity'];
    $listing_email  $HTTP_POST_VARS['txtlistingemail'];
    $listing_emailoption  $HTTP_POST_VARS['rademailoption'];
    $listing_contactinfo  $HTTP_POST_VARS['txtlistingcontactinfo'];
    $listing_date  $HTTP_POST_VARS['txtlistingdate'];
    $listing_show  "N";
    $listing_buysell  $HTTP_POST_VARS['radfor'];
    $listing_premier  $HTTP_POST_VARS['chkpremier'];
    if(
    $listing_premier=="on"){
        
    $listing_premier "Y";
    }else{
        
    $listing_premier "N";
    }
    $listing_date date("Y-m-d");

    if(isset(
    $HTTP_GET_VARS['mode']))
    {
        
    $mode =$HTTP_GET_VARS['mode'];
    }
    if(isset(
    $HTTP_POST_VARS['mode']))
    {
        
    $mode =$HTTP_POST_VARS['mode'];
    }
    $frmpg $HTTP_POST_VARS['txtfrmpg'];
    $dirupload "images/listing/";

    switch (
    $mode){
    case 
    "Add":
    //-- RE-SIZING UPLOADED IMAGE

        /*== only resize if the image is larger than 600 x 600 ==*/
        
    $imgsize GetImageSize($listingimage);

        
    /*== check size  0=width, 1=height ==*/
        
    if (($imgsize[0] > 600) || ($imgsize[1] > 600))
        {
              
    /*== if an error occurs the file could not
                   be written, read or possibly does not exist ==*/
              
    print "Your File is to large. Maximum file dimensions are 600px x 600px.";
              exit();
           }

    $max_filesize_k = ($max_filesize 500);

    if(
    $_FILES['$listingimage']['size'][$i] > $max_filesize)
    {
       echo 
    "Your file is too large.  Files may be up to ".$max_filesize_k."K\n";
       include(
    "listingentry.php");
       exit;
    }
            if(
    $HTTP_POST_FILES['txtlistingimage']['name'] == ""){
                
    $listing_image "";
            }else{
                
    $listing_image getfilename($HTTP_POST_FILES['txtlistingimage']['name'],1);
                
    copy $HTTP_POST_FILES['txtlistingimage']['tmp_name'],$dirupload.$listing_image)
                or 
    $msgid=2;
            }
                
    $strInsert="Insert into listing_master(city_id,category_id,listing_title,listing_location,listing_price,listing_text,listing_address,listing_city,listing_image,listing_email,listing_email_option,listing_contact_information,listing_date,listing_show,listing_buysell,listing_premier) values (";
            if(
    $listing_date == ""){
                
    $strInsert=$strInsert "$city,$c_id,'$listing_title','$listing_location',$listing_price,'$listing_text','$listing_address','$listing_city','$listing_image','$listing_email','$listing_emailoption','$listing_contactinfo',NULL,'$listing_show','$listing_buysell','$listing_premier')";
            }else{
                   
    $strInsert=$strInsert "$city,$c_id,'$listing_title','$listing_location',$listing_price,'$listing_text','$listing_address','$listing_city','$listing_image','$listing_email','$listing_emailoption','$listing_contactinfo','$listing_date','$listing_show','$listing_buysell','$listing_premier')";
            }
            
    $MsgId=1;
            if(!(
    $dbResult mysql_query($strInsert$dbLink)))
            {
                
    $success "false";
                
    $MsgId=2;
            }
    //        $ssql = "SELECT max(listing_id) as listing_id FROM listing_master";


    //        $dbResultid = mysql_query($ssql,$dbLink);
    //        $rowlistid = mysql_fetch_array($dbResultid, MYSQL_ASSOC);
    //        $listingid = $rowlistid['listing_id'];
            
    $listingid mysql_insert_id();
              
    header("Location:listingpreview.php?l_id=$listingid&cityid=".$city."&c_id=$c_id&catid=$c_id&msgid=".$MsgId);
            return;
               break; 
    Last edited by monki_SF; 03-12-2006 at 08:05 PM.

  12. #27
    Join Date
    Sep 2005
    Posts
    1,633
    hi Bokeh,
    your script now works. Hosting provider has fixed this permission problem.

  13. #28
    Join Date
    Sep 2004
    Location
    Sunbury, PA
    Posts
    70
    Fantastic script!

    How can I get the images to be viewable after they are uploaded. Is this something that has to be done manually or is there a scipt I can place into a page to make the images viewable?

    Thanks in advance.

    Har
    Harry Kerstetter
    President
    Tylivia Web Design
    Browser: Firefox 2 beta 2
    Resolution: 1440 X 900
    Development Tools:
    Macromedia/Adobe Studio 8
    Adobe Illustrator CS
    SWiSH Max
    PHP Designer 2005
    Favorite Quote:"In completing one discovery we never fail to get an imperfect knowledge of others of which we could have no idea before, so that we cannot solve one doubt without creating several new ones." - Joseph Priestly, 1786

  14. #29
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    store in a database and display the results where you want

  15. #30
    Join Date
    Sep 2005
    Posts
    1,633
    Quote Originally Posted by tylivia
    How can I get the images to be viewable after they are uploaded.
    Would you like FTP view or showing results on web site?

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