Page 21 of 23 FirstFirst ... 111920212223 LastLast
Results 301 to 315 of 340

Thread: How to: Upload images using PHP

  1. #301
    Join Date
    Dec 2009

    I want to keep it simple (file names :-)

    How can I let an uploaded file overwrite an existing file that has the same name?

    I was able to comment out the code in the upload processor file that creates a unique filename for the uploaded file, but I get a server error if that file name already exists.

    I want to keep it really simple so the files can be named ID1.jpg, ID2.jpg etc.

  2. #302
    Join Date
    Jun 2008
    Quote Originally Posted by bokeh View Post
    If you want to retain the filename but check there is no collission you could do something like this:
    PHP Code:
    $FieldName 'images';
    $UploadsFolder 'uploads/';
    $output '';
    $MaxAttempts 50;

    $_FILES[$FieldName]['error'] as $k => $v)
    === $v)
    file_exists($Filename $UploadsFolder $_FILES[$FieldName]['name'][$k]))
    $MaxAttempts > ++$v and file_exists(
    $MaxAttempts $v or die('Please rename ' $_FILES[$FieldName]['name'][$k]);
    move_uploaded_file($_FILES[$FieldName]['tmp_name'][$k], $Filename))
    $output .= "<p><em>{$_FILES[$FieldName]['name'][$k]}</em> saved OK!</p>\n";
    $output or $output '<p>No files were saved</p>';
    Newbie here - where would the above go or replace in the multiple.upload.processor.php?

    Quote Originally Posted by knightman View Post
    fwrite($h, "$now-".$_FILES[$fieldname]['name'][$key]."."\r\n");
    This line is giving me two errors:
    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ... multiple.upload.processor.php on line 92

    Parse error: syntax error, unexpected T_STRING in ... multiple.upload.processor.php on line 92
    Awesome script, btw. Regarding thumbnails I am just using phpThumb.

  3. #303
    Join Date
    Dec 2009
    Hello, thanks for multiuploader. But I need some help. I want upload into 2 directories.

    So file1 in directory1 and file2 in directory2.. Is it possible? Thanks

  4. #304
    Join Date
    Jan 2010
    i am testing the multiple image uploader and i getting the following error:

    HTML Code:
    An error has occured: : ...  The upload form is reloading
    thanks for your help!

  5. #305
    Join Date
    Mar 2010

    Permissions error

    Hi guys, ive looked all over and followed some peoples suggestions but i cannot get these scripts to work.

    Every time i attempt to upload images, i get the 'insufficient permission' error.

    Using filezilla i have set the 'uploaded_files' directory to '777'.

    I really have know idea how to solve this as the code clearly works for others.

    Any help whatsoever will be much appreciated.

    Thanks in advance

  6. #306
    Join Date
    Jun 2008

    I don't know if this thread is still supported but I have a question regarding MULTIPLE image uploads.

    I would like people to upload two images (Husband and Wife).
    I have two columns in my MySQL database (husband, wife)

    What code do I used to store both file paths to the images in their proper places in the database?

    Thank you
    Kind regards

  7. #307
    Join Date
    Jun 2008
    Nevermind, I just solved the coding problem by myself (YUSS!!)

    Another question:

    If I want these images to expire after a year, is there some way to automatically delete these files out of my images folder?

    I can image after a few years that the folder would just get too huge if nothing got deleted.

  8. #308
    Join Date
    Jan 2005
    Alicante (Spain)
    Save the upload date in your DB and every so often delete the ones older than a certain age. Could be set up as a cron job.

  9. #309
    Join Date
    Jun 2008
    Quote Originally Posted by bokeh View Post
    Save the upload date in your DB and every so often delete the ones older than a certain age. Could be set up as a cron job.

    Awesome, so I can set up a cron job to delete the image itself in my "images" folder?

    Do you know how to set this up? I know how to delete things out of the database but I don't know how to set up a program to delete actual files in a folder.

  10. #310
    Join Date
    Jan 2010
    I've got problems with a pre-existing upload form, its quite a long thing so I posted it elsewhere:

    link here

    If someone could help me I'd really appriciate it, it seems like it should upload fine but it just... doesnt.
    L.U.N.E for anyone and everyone who has an interest in literature

  11. #311
    Join Date
    Jul 2011
    I realize the last post on this thread is a year ago but it still comes up high on the list of Google searches for multiple file uploads. I tested the code and it works great(in fact the best I found), but I need to add the names of the uploads to a database. I read through the whole thread and saw the addendum that allows for this but it seems to add each image as a separate record. I want to add up to 8 images to a single record (along with other info). Arrays always give me headaches! I can't figure out where or how to add to the code. I need to add the images to fields image1, image2, image3 etc. Any help greatly appreciated!

  12. #312
    Join Date
    Dec 2004
    You need to post some code so you can be helped.

  13. #313
    Join Date
    Jul 2011
    OK, this is the form:
    // filename: multiple.upload.form.php
    // first let's set some variables
    // 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 location of the upload handler
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.processor.php';
    // set a max file size for the html upload form
    $max_file_size = 300000; // size in bytes
    // now echo the html page
    <html lang="en">
    		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    		<link rel="stylesheet" type="text/css" href="stylesheet.css">
    <title>Upload form</title>
    <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">
    <h1>Upload form</h1>
    <p><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>"></p>
    <p><label for="location">Location:</label>
    <input type="text" name="location">
    <p><label for="description">Description:</label>
    <input type="text" name="description">
    <p><label for="image1">File to upload:</label>
    <input id="image1" type="file" name="file[]">
    <p><label for="image2">File to upload:</label>
    <input id="image2" type="file" name="file[]">
    <p><label for="image3">File to upload:</label>
    <input id="image3" type="file" name="file[]">
    <label for="submit">Press to...</label>
    <input id="submit" type="submit" name="submit" value="Upload us!">
    I added the following to the original code on the processor page
    $q = "INSERT INTO properties ('location','description','image1','image2','image3') VALUES ('$location','$description',";
    foreach($active_keys as $key)
    	$q .= "'$uploadFilename',"; 
    $q .= ")";
    echo $q;
    What I get with the echo is
    [QUOTE]INSERT INTO properties ('location','description','image1','image2','image3') VALUES ('Main Street','2 unit townhouse','Array','Array','Array',)[QUOTE]

    So 2 problems:

    1. how do I get the actual name of the file and
    2. how do I get rid of the final comma in the query.

  14. #314
    Join Date
    Jul 2011
    I should add that immediately before the code I added is the following
    // 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);
    which is where the $uploadFilename in my query came from.

  15. #315
    Join Date
    Jul 2011
    OK I see part of my error now. So I replaced

    in the query and I get the file name, including the whole path from c:

    If I echo this

    foreach($active_keys as $key)
    	echo $_FILES[$fieldname]['name'][$key];
    I get the simple names of the files without the path. Somehow I have to put each file name into a variable like $filename1, $filename2, etc. up to $filename8 and add it to the query. The problem is I don't know how to build an array to do that. Also, the user may not upload 8 files so I'll get an error in my query if there are fewer images. I've been struggling with this for days now, so if anyone can help you'll save me from pulling out my hair
    Last edited by Calagoure; 07-07-2011 at 12:19 PM.

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14695 seconds
  • Memory Usage 3,050KB
  • Queries Executed 15 (?)
More Information
Template Usage (40):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (74):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates