Copy Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Copy Problem

Post by chris12295 »

I have an image gallery. User selects image, it copies to a tmp directory, make a thumbnail into photos/thumbs, then copies tmp image to photos folder.

Now lets say we have a folder with 2 jpg images. In my case, one would work perefectly but the other wouldnt copy to the tmp directory.

What could be causing this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

could you post the code, and exact filenames involved?
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

copy function:

Code: Select all

function add_pic()
 {
  $tmp_name = 
  if(empty($_FILES[pic][name]))
   {
    $error = 1;
	$GLOBALS[pic_message] = 'Please select a (.JPG) file';
   }
  if(!$error)
  {
   echo $_FILES[pic][tmp_name];
   $dir = $_SERVER["DOCUMENT_ROOT"]."/Courtney/admin/tmp/";
   $newname = "pic".time().".jpg";
   $newfile = $dir . $newname;
   copy($_FILES[pic][tmp_name], $newfile);
   $dimensions = getimagesize($newfile)or die("Error");
   if($dimensions[2] != 2)
    {
     $error = 1;
     $GLOBALS[pic_message] = "Only use files with .JPG extensions.";
    }
  }
  if(!$error)
  {
   $width = $dimensions[0];
   $height = $dimensions[1];
   $query = mysql_query("SELECT id from pics");
   while($row=mysql_fetch_array($query))
    {
     $src = $row[id];
    }
   $src +=1;
   $c = imagecreatefromjpeg($newfile);
   /*y=height x=width*/
   $dst_width=(($width*70)/$height);
   if($dimensions[2] == 2)
    {
     $b = imagecreatetruecolor($dst_width, 70);
     $ext = "JPG";
    }
   if($ext == "JPG")
    {
     imagecopyresampled($b, $c, 0, 0, 0, 0, $dst_width, 70, $width, $height);
	 copy($newfile, "../images/photos/$src.jpg");
     imagejpeg($b, "../images/photos/thumbs/$src.jpg", 100);
    }
   mysql_query("INSERT into pics (src) VALUES($src)");
   $_REQUEST[pic]='';
   if(file_exists($newfile)) unlink($newfile);
  }
 else 
  {
   include("add_pic.php");
   die;
  }
 }
form code:

Code: Select all

<form enctype="multipart/form-data" action="index.php" method="post">
 <input type="hidden" name="MAX_FILE_SIZE" value="99999">
 <input type="hidden" name="process" value="add_pic">
<table>
<tr><td colspan=3><span class='head1'>Add Picture</span></td></tr>
<tr><td bgcolor="#CCCCCC"><b class='form_text'>Picture File:</b> </td><td bgcolor="#999999"><input type="file" name="pic"></td><td bgcolor="#FFFFFF"><span class="error_message"><?=$GLOBALSїpic_message]?></span></td></tr>
<tr><td bgcolor="#CCCCCC"><b class='form_text'>Add Another Picture:</b> </td> <td bgcolor="#999999"><span class="form_text">Yes</span><input type="checkbox" name="page" value="add_pic" <?if(!empty($_REQUESTїpage]) and !empty($_REQUESTїsubmit])) echo "CHECKED";?>></td><td bgcolor="#FFFFFF"><img src="../images/interface/spacer.gif"></td></tr>
<tr><td colspan=2 align='center'><input name="submit" type="submit" value="Add Picture"></td></tr>

</table>
</form>
Names of files that don't work: April302003002.jpg, CourtneyVehnekampWebsitePhoto#1, February232003-Sweet16etc.073.jpg, February232003-Sweet16etc.081.jpg, Bonnie019.jpg, Bonnie021.jpg, Bonnie024.jpg, Bonnie075.jpg, Bonnie086.jpg

files that do work: BillCosbyPhoto.jpg, CourtneyVehnekamp.jpg


also, i just noticed that the two that work dont have numbers and all the rest do??
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

maybe

Post by fresh »

the file names are way to big, I would shorten them to no more than 8 chars, could just be overwhelming the script, or perhaps, like you said the numbers are conflicting with the script... gd lk
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

well i tried that, i renemaed the april one to April.jpg but it still didnt work.

Then i copied the picture in one that didnt work to one that did, then the one that worked didnt work anymore.

So, could it be affected by the image size, resolution or the way it was saved i.e(Baseline standard, progressive...)?

i have max_upload_file size set to 10000M in my file, is that the right format?

is there a resolution setting?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nothing pops out to me, however, your habit of not quoting strings raises an eyebrow and somehow, may be apart of the problem...

progressive files may not be compatible with GD, I don't quite know.
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

YAY!!!! I GOT IT!!!!! It was on my form, for some reason i was thinking in KB for the max_file_size, but its bytes, i just increased it to 1000000, now it works
User avatar
fresh
Forum Contributor
Posts: 259
Joined: Mon Jun 14, 2004 10:39 am
Location: Amerika

hey

Post by fresh »

doesnt this look wrong feyd:

Code: Select all

if(file_exists($newfile)) unlink($newfile);
  }
else
  {
   include("add_pic.php");
   die;
  }
}
shouldn't it be more like this:

Code: Select all

if(file_exists($newfile)) unlink($newfile) {  <-- added bracket got rid of semi colon
  } else {
   include("add_pic.php");
   die;
  }
}  <-- may not need this one
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

nope, it was alright.
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

no that worked, i have noticed on a lot of things where u specify filesizes and filelengths that a lot of 9's wont work and a lot of 0's wont either, ususally less than 10 billion works
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

anything past 2,147,483,648 or 4,294,967,296 goes beyond the "standard" size the number can hold..
Post Reply