20i Reseller Hosting

PHP error - Image upload

Discussion in 'Scripts and Coding' started by theonemanyuri, Mar 3, 2014.

Thread Status:
Not open for further replies.
  1. theonemanyuri

    theonemanyuri Active Member

    Joined:
    Jun 2010
    Posts:
    556
    Likes Received:
    2
    I've been following a tutorial online to build my own CMS, as a way to learn php code alongside some books I'm reading. Unfortunately the site where the tutorial lives seems to be dead so I can't get any help there (http://www.elated.com/articles/add-image-uploading-to-your-cms/).

    I get the following error after I've selected an image to upload and click 'save changes' on the editarticle.php page:

    Warning: move_uploaded_file(/images/articles/fullsize/13.jpg): failed to open stream: No such file or directory in E:\xampp\htdocs\test\cms\classes\article.php on line 104

    Warning: move_uploaded_file(): Unable to move 'E:\xampp\tmp\phpA387.tmp' to '/images/articles/fullsize/13.jpg' in E:\xampp\htdocs\test\cms\classes\article.php on line 104

    Fatal error: Article::storeUploadedImage(): Couldn't move uploaded file. in E:\xampp\htdocs\test\cms\classes\article.php on line 104

    Line 104 reads:

    if ( !( move_uploaded_file( $tempFilename, $this->getImagePath() ) ) ) trigger_error( "Article::storeUploadedImage(): Couldn't move uploaded file.", E_USER_ERROR );

    I appreciate it's a fair amount of code to look through potentially to find the issue, I was just hoping there might be a glaring mistake here that might jump out to someone who knows what they're doing! Cheers
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
    articles.co.uk
     
  3. klap United Kingdom

    klap Member

    Joined:
    Mar 2012
    Posts:
    37
    Likes Received:
    1
    Have you made sure that /images/articles/fullsize/ folders all exist? And once they're created ensure they're writeable (0777).
     
  4. theonemanyuri

    theonemanyuri Active Member

    Joined:
    Jun 2010
    Posts:
    556
    Likes Received:
    2
    Yep all folders exist and paths are correct. I did think it may be a permissions issue, I'm using XAMPP on windows 8. I've made all folders have full permissions for all users (right click, security tab), is that sufficient?
     
  5. seemly

    seemly Well-Known Member

    Joined:
    Feb 2011
    Posts:
    1,227
    Likes Received:
    193
    In some cases, I have experienced this same issue. After creating a new directory, file permissions were no longer an issue, but try and save into the directory with issues - even when trying to define permissions via CLI - the issue still exists.
     
  6. theonemanyuri

    theonemanyuri Active Member

    Joined:
    Jun 2010
    Posts:
    556
    Likes Received:
    2
    Hmm, I've tried creating new files and changing file paths, but it didn't make any difference...

    The next line in 'article.php' is an error function to do with permissions and I've never seen that, so it may not be permission related. Similarly, it could just be that the program doesn't get far enough to throw up that error.
     
  7. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,658
    Likes Received:
    136
    Set debug points, and see where it stops.

    The errors you posted appear to suggest no file was uploaded, or it was unable to write the uploaded data, which in my experience would mean your php interpreter doesn't know where your tmp folder is (which is common on windows machines and less so on *nix) or target folder isn't writable by the user running the script.
     
  8. theonemanyuri

    theonemanyuri Active Member

    Joined:
    Jun 2010
    Posts:
    556
    Likes Received:
    2
    The tmp folder did cross my mind, I've just checked the config .ini for XAMPP and the path is listed to the correct tmp folder (E:\xampp\tmp), it also has stuff in it. However, nothing matching 'phpA387.tmp' or similar that should be created during this image upload...
     
  9. Skinner

    Skinner Well-Known Member

    Joined:
    Jul 2008
    Posts:
    4,658
    Likes Received:
    136
    phpA387.tmp is the temp image file, which is where its put upon upoading, before its renamed and moved.

    Have you tried a simple upload script ?
     
  10. theonemanyuri

    theonemanyuri Active Member

    Joined:
    Jun 2010
    Posts:
    556
    Likes Received:
    2
    I've managed to get it working, I downloaded the full code from the site then piece by piece put my own code back into it... I think the problem was something as spurious as a lowercase in the wrong place (editarticle instead of editArticle) in one instance. Thanks for your help
     
Thread Status:
Not open for further replies.