Jump to content

image upload script issue ...


techiefreak05

Recommended Posts

Hi, I have an image upload script that is having some issues ...  It says its uploads just fine, but it doesn't, can anybody see why?

[code]
<?php
if($_POST["action"] == "-Upload-") {
  unset($picfile_name); //Prevent from uploading Again! :P
  if(! isset($_FILES['image_file'])) {
  $error = "An image was not found.";
  }
  $max_space = 524288; //.5 mg
  $files = array("image/gif", // Gif
        "image/jpeg", // jpe jpeg jpg
        "png", // PNG
        );
  $picfile_name = $_FILES['image_file']['name'];
  $picfile_type = $_FILES['image_file']['type'];
  $picfile_size = $_FILES['image_file']['size'];
  $picfile_temp = $_FILES['image_file']['tmp_name'];
  $dir = "files/uploads/" . $_SESSION[username];
 
  if(empty($picfile_name)) {
  $error = "The name of the image was not found.";
  }
  if($picfile_size >= $max_space) {
  $error = "Image was too big!";
  }
  if(! in_array($picfile_type, $files)) {
  $error = "File was not allowed! Only gif,png,jpg,jpeg!";
  }
  if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) {
  $error = "Upload Error! (HACKER ATTACK!)";
  }
  if(file_exists($dir.$picfile_name)) {
  $error = "A file with that name was already uploaded to your account!";
  }
  if($error != '') {
  echo $error;
  exit();
  }
  $ff = $dir . "/" . $picfile_name;
  if(move_uploaded_file($picfile_temp, $picfile_name)) {
  mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us/$ff','','','$_SESSION[id]')") or die(mysql_error());
  echo '<font color="red">Image Upload Successful!!</font> <a
href="imageUpload.php" class="blue">Refresh Page</a>';
  } else {
  echo 'Could not upload file!';
  exit();
  }
} else {
  ?>
<div id="form">
<b>Upload Form</b>
<center>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>">
<p><input type="file" name="image_file" size="20" /></p>
<p><input type="submit" value="-Upload-" name="action" /></p>
</form>
</center>
</div>
<?php
}
?>
[/code]
Link to comment
Share on other sites

Try doing this:
[code]
if(!move_uploaded_file($orginalfile, $targetfile){echo "file upload failed...";}
else{echo "upload successful";}
[/code]
try this if the above doesnt work:
[code]
$upload = move_uploaded_file($orginalfile, $targetfile).........//whatever action you want to do after that
if ($upload === false){echo "file upload failed";} else {echo "upload successful";}

Try those, i am not sure if they will work or not, but give it a try
Ted[/code]
Link to comment
Share on other sites

it says it works ... but it doesnt even upload the picture.. heres the code i have:

[code]<?php
if($_POST["action"] == "-Upload-") {
  unset($picfile_name); //Prevent from uploading Again! :P
  if(! isset($_FILES['image_file'])) {
  $error = "An image was not found.";
  }
  $max_space = 524288; //.5 mg
  $files = array("image/gif", // Gif
        "image/jpeg", // jpe jpeg jpg
        "png", // PNG
        );
  $picfile_name = $_FILES['image_file']['name'];
  $picfile_type = $_FILES['image_file']['type'];
  $picfile_size = $_FILES['image_file']['size'];
  $picfile_temp = $_FILES['image_file']['tmp_name'];
  $dir = "/files/uploads/" . $_SESSION[username];
 
  if(empty($picfile_name)) {
  $error = "The name of the image was not found.";
  }
  if($picfile_size >= $max_space) {
  $error = "Image was too big!";
  }
  if(! in_array($picfile_type, $files)) {
  $error = "File was not allowed! Only gif,png,jpg,jpeg!";
  }
  if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) {
  $error = "Upload Error! (HACKER ATTACK!)";
  }
  if(file_exists($dir.$picfile_name)) {
  $error = "A file with that name was already uploaded to your account!";
  }
  if($error != '') {
  echo $error;
  exit();
  }
  $ff = $dir . "/" . $picfile_name;
$upload = move_uploaded_file($picfile_temp, $picfile_name);
if($upload){
  mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error());
  echo '<font color="red">Image Upload Successful</font> <a
href="imageUpload.php" class="blue">Refresh Page</a>';
  } else {
  echo 'Could not upload file!';
  exit();
  }
} else {
  ?>
<div id="form">
<b>Upload Form</b>
<center>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>">
<p><input type="file" name="image_file" size="20" /></p>
<p><input type="submit" value="-Upload-" name="action" /></p>
</form>
</center>
</div>
  <?php
}
?>[/code]
Link to comment
Share on other sites

try this:
[code]
<?php
if($_POST["action"] == "-Upload-") {
  unset($picfile_name); //Prevent from uploading Again! :P
  if(! isset($_FILES['image_file'])) {
  $error = "An image was not found.";
  }
  $max_space = 524288; //.5 mg
  $files = array("image/gif", // Gif
        "image/jpeg", // jpe jpeg jpg
        "png", // PNG
        );
  $picfile_name = $_FILES['image_file']['name'];
  $picfile_type = $_FILES['image_file']['type'];
  $picfile_size = $_FILES['image_file']['size'];
  $picfile_temp = $_FILES['image_file']['tmp_name'];
  $dir = "/files/uploads/" . $_SESSION[username];
 
  if(empty($picfile_name)) {
  $error = "The name of the image was not found.";
  }
  if($picfile_size >= $max_space) {
  $error = "Image was too big!";
  }
  if(! in_array($picfile_type, $files)) {
  $error = "File was not allowed! Only gif,png,jpg,jpeg!";
  }
  if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) {
  $error = "Upload Error! (HACKER ATTACK!)";
  }
  if(file_exists($dir.$picfile_name)) {
  $error = "A file with that name was already uploaded to your account!";
  }
  if($error != '') {
  echo $error;
  exit();
  }
  $ff = $dir . "/" . $picfile_name;
$upload = move_uploaded_file($picfile_temp, $picfile_name);
if($upload === true){
  mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error());
  echo '<font color="red">Image Upload Successful</font><a
href="imageUpload.php" class="blue">Refresh Page</a>';
  } else {
  echo 'Could not upload file!';
  exit();
  }
} else {
  ?>
<div id="form">
<b>Upload Form</b>
<center>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>">
<p><input type="file" name="image_file" size="20" /></p>
<p><input type="submit" value="-Upload-" name="action" /></p>
</form>
</center>
</div>
  <?php
}
?>
[/code]
Link to comment
Share on other sites

[code]
<?php
if($_POST["action"] == "-Upload-") {
  unset($picfile_name); //Prevent from uploading Again! :P
  if(! isset($_FILES['image_file'])) {
   $error = "An image was not found.";
  }
  $max_space = 524288; //.5 mg
  $files = array("image/gif", // Gif
        "image/jpeg", // jpe jpeg jpg
        "png", // PNG
        );
  $picfile_name = $_FILES['image_file']['name'];
  $picfile_type = $_FILES['image_file']['type'];
  $picfile_size = $_FILES['image_file']['size'];
  $picfile_temp = $_FILES['image_file']['tmp_name'];
  $dir = "/files/uploads/" . $_SESSION[username];
 
  if(empty($picfile_name)) {
   $error = "The name of the image was not found.";
  }
  if($picfile_size >= $max_space) {
   $error = "Image was too big!";
  }
  if(! in_array($picfile_type, $files)) {
   $error = "File was not allowed! Only gif,png,jpg,jpeg!";
  }
  if(! is_uploaded_file($_FILES['image_file']['tmp_name'])) {
   $error = "Upload Error! (HACKER ATTACK!)";
  }
  if(file_exists($dir.$picfile_name)) {
   $error = "A file with that name was already uploaded to your account!";
  }
  if($error != '') {
   echo $error;
   exit();
  }
  $ff = $dir . "/" . $picfile_name;
$upload = move_uploaded_file($picfile_temp, $ff);
if($upload === true){
   mysql_query("INSERT INTO `images` (`imgPath`,`headline`,`id`,`userid`) VALUES ('http://s191754240.onlinehome.us$ff','','','$_SESSION[id]')") or die(mysql_error());
   echo '<font color="red">Image Upload Successful</font><a
href="imageUpload.php" class="blue">Refresh Page</a>';
  } else {
   echo 'Could not upload file!';
   exit();
  }
} else {
  ?>
<div id="form">
<b>Upload Form</b>
<center>
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<? $_SERVER["PHP_SELF"]; ?>">
<p><input type="file" name="image_file" size="20" /></p>
<p><input type="submit" value="-Upload-" name="action" /></p>
</form>
</center>
</div>
  <?php
}
?>
[/code]
tell me if worked...
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.