Jump to content

[SOLVED] Uploading Aint Likin Me


kurios

Recommended Posts

Anytime i upload a image, i get the following errors:

 

Warning: move_uploaded_file(/var/chroot/home/content/k/u/r/kuriomister/html/images/png8.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/k/u/r/kuriomister/html/temp/update.php on line 143

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpbzDIHH' to '/var/chroot/home/content/k/u/r/kuriomister/html/images/png8.jpg' in /home/content/k/u/r/kuriomister/html/temp/update.php on line 143

 

 

and i cant seem to find out why :( anyone have any ideas, cause im running out (yes, my php is configured for uploading). Its on a shared linux host.

HTML Code:

 

<FORM ENCTYPE="multipart/form-data" ACTION="update.php" METHOD="post" name="upload" id="upload">

<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="2000000">


<B>Image:</B><BR>
<INPUT TYPE="file" id="image" name="image" VALUE="" SIZE="60" MAXLENGTH="100"><BR>
<BR>
<BR>

<INPUT TYPE="SUBMIT" VALUE="Upload Image">
</FORM>

 

 

 

PHP code:

[tt]
<?php

$error = '';

//test for error
if ($_FILES['image']['error'] > 0) {
  switch ($_FILES['image']['error']) {
    case 1: $error = 'Error[1]: Size exeeded maximum file size allowed.<BR><BR><BR>';
    case 2: $error = 'Error[2]: Size exeeded maximum file size allowed.<BR><BR><BR>';
    case 3: $error = 'Error[3]: File only partially uploaded<BR><BR><BR>';
    case 4: $error = 'Error[4]: No file uploaded<BR><BR><BR>';
  }
}

if ($error == '') {
$upfile = $_SERVER['DOCUMENT_ROOT'].'/images/'.$_FILES['image']['name'];
  if (is_uploaded_file($_FILES['image']['tmp_name'])) {
    if (!move_uploaded_file($_FILES['image']['tmp_name'], $upfile)) {
       $error = 'Error: Couldn\'t move file to destination directory<BR><BR><BR>';
    }
  }else{
    $error = 'Error: Image not uploaded';
  }
} 

if ($error == '') {

  echo '<IMG SRC="'.$DOCUMENT_ROOT.'/images/'.$_FILES['file']['name'].'"><BR>';
  echo '<B>FILE UPLOADED:</B><BR><BR><HR><I>'.$_FILES["file"]["name"].'successfully uploaded<BR></I><HR><BR><BR>\n';
  echo '<A HREF="eventimages.php">Add Another Image</A><BR>';


}else{
  echo $error;
}
?>[/tt]

 

Link to comment
Share on other sites

when you move an uploaded file to a folder, you start with the folder name, not a "/" and you dont need any document root stuff. so go from:

 

$upfile = $_SERVER['DOCUMENT_ROOT'].'/images/'.$_FILES['image']['name'];

 

to

 

$upfile = 'images/'.$_FILES['image']['name'];

 

This is bc the move_uploaded_file moves relative to the current position. So if you root folder is public_html and you have the upload script there, you can't do "move uploaded file to 'public_html/images/image.jpg' " because there is no folder called public_html in your public_html folder.(if that made sense)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.