Jump to content

File Upload Error


mcerveni

Recommended Posts

Hey guys, i recently re installed apache 2.2 php 5.2.5 and mysql 5.0,

some of my upload scripts work, and some do not, and i'm not too sure why?

 

here is my form:

<form action="processUpload.php?album=<?php echo $session ?> " method="post" enctype="multipart/form-data">
<table align="center">
<tr><td> 

<?php if ($_GET['upload'] == "1") { //if the file has been added the processUpload.php page brings 
//you back to index.php?upload=1 if upload = 1 then show this msg. ?>
<div align="center"> 
<div align="center"> <div id="userAdded"> Your picture has been added. </div>
</div>
<?php } ?>

<table align="center" id="photogallery">
<!-- Add div tage here for a header -->
<div id="photogalleryHeader"> Upload Pictures || <?php echo $album ?> </div>

<?php if ($_GET['err'] == 1) { ?>
<tr><td> <font color="red"> *Please select an image to upload </font> </td></tr>
<?php } ?>


<tr><td>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
Upload Pictures:<br> <input name="photo" type="file"> 
</td> 
<td>  
<textarea  name="caption" rows="2" cols="30"> insert caption here... </textarea> </td>

</tr>
<tr><td> <input type="submit" name="submit" value="Start Upload"> </td></tr>     
</table>
</td></tr>
</table>
</form>

 

here is the processUpload page:

 

$fileName = $_FILES['photo']['name'];
$tmpName  = $_FILES['photo']['tmp_name'];
$fileSize = $_FILES['photo']['size'];
$fileType = $_FILES['photo']['type'];

$pic=($_FILES['photo']['name']);
$caption = $_POST['caption'];
$album = $_GET['album']; //this is in the url processUpload.php?album=$session

$dir = str_replace(" ", "_", $album);

$target = "../../photogallery/$dir/";
$target = $target . basename( $_FILES['photo']['name']); 


if (isset($_POST['submit'])) { 

   if (!is_uploaded_file($HTTP_POST_FILES['photo']['tmp_name'])) {
    unlink($HTTP_POST_FILES['photo']['tmp_name']);
    header('Location:uploadPictures.php?err=1');
    exit();
    
    }
    


  	
$query = "INSERT INTO photogallery (photo_id, dir, album, photo, caption) 
	  VALUES (0, '$dir', '$album', '$pic', '$caption' )  ";
  

	  
//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 
      //CHECK TO SEE IF THE QUERY HAS BEEN SUBMITTED OKAY. 
      if( @mysql_query ($query) ){ 
          header('Location:uploadPictures.php?album='.$album.'');
          exit();
       } 
    
}


}

 

it just gives me my own error: *Please select an image to upload

any ideas??

Link to comment
https://forums.phpfreaks.com/topic/102923-file-upload-error/
Share on other sites

i figured out why it wasn't working..

 

when i took out http_post_files, then it worked perfectly.

 

if (isset($_POST['submit'])) { 

   if (!is_uploaded_file($HTTP_POST_FILES['photo']['tmp_name'])) {
    unlink($HTTP_POST_FILES['photo']['tmp_name']);
    header('Location:uploadPictures.php?err=1');
    exit();
    
    }

 

i just installed php5.2.5 and it seems like it's not recognizing $HTTP_POST_FILES....why is that??

Link to comment
https://forums.phpfreaks.com/topic/102923-file-upload-error/#findComment-527253
Share on other sites

i just commented that whole section:

 

// if (!is_uploaded_file($HTTP_POST_FILES['photo']['tmp_name'])) {

  // unlink($HTTP_POST_FILES['photo']['tmp_name']);

    //header('Location:uploadPictures.php?err=1');

    //exit();

   

    //}

 

is there another way to figure out if there was a file picked to upload?

 

 

Link to comment
https://forums.phpfreaks.com/topic/102923-file-upload-error/#findComment-527254
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.