You are not logged in.
#1 2006-08-04 16:58:12
- matthijs
- Member
Fixing zip upload
Hey,
zip upload was not working for me, so I looked around a bit in the code to fix it. In admin.class.php, I found at line 1296:
Code:
$contents = $this->getListing($wd,"images");
This line will, after unzipping the zip file, look what files are in the file. The second argument, "images", is taken as a regular expression for filename extensions. So, this line says, look for files that end in ".images". I'm not sure why this is here, but I suspect the getListing function got changed in the past?
Anyway, removing the last argument here fixes the problem. Perhaps the last argument should be something like "(jpg|gif|png)"?
A few lines further on, there is another call to getListing(), for which the same changes are required.
Does this make sense? Could this be included in the next release?
Offline
#2 2006-08-04 18:18:15
- Paul
- Member
Re: Fixing zip upload
There's a list of recognised extensions in singapore.ini (towards the bottom of the file). Maybe the call to this getListing function should incorporate those extensions somehow...?
Offline
#3 2006-08-04 19:27:53
- pavian
- Moderator

Re: Fixing zip upload
Okay, I think you are right I fixed that in cvs. I hope tamlyn will double check it:
line should read:
Code:
$contents = $this->getListing($wd,$this->config->recognised_extensions);
Offline
#4 2006-09-14 16:04:00
- sparkybarkalot
- Member
Re: Fixing zip upload
I was having a problem with zip uploads as well, and I made the change given by pavian and they started working. thanks everyone!
Offline
#5 2006-09-18 21:49:43
- fotogeek
- Member
Re: Fixing zip upload
I'd like to make this fix, but I can't see what you wrote Pavian, it just says Code: and a scroll bar, without any code.
Oh, also, when you say "a few lines down" you need to make the same change, but the code is different a few lines down. It's:
Code:
$contents = $this->getListing($wd,$this->config->recognised_extensions);
I assume that's the line you're talking about. Does that change need to happen with both? Same change?
Last edited by fotogeek (2006-09-18 21:57:58)
Offline
#6 2006-09-18 21:58:51
- pavian
- Moderator

Re: Fixing zip upload
hmm, what browser are you using fotogeek? A geeky one I suppose .. ah wait no - let me guess: Internet Explorer...this browser needs an extra line break:
Code:
//this is just for the line break $contents = $this->getListing($wd,$this->config->recognised_extensions);
Offline
#7 2006-09-18 22:00:51
- pavian
- Moderator

Re: Fixing zip upload
hmm..well I hope you can see it now.. kinda strange, but the code is that long.
Offline
#8 2006-09-18 22:15:37
- fotogeek
- Member
Re: Fixing zip upload
lol, yes, not geeky enough.
I made those changed but it still didn't help. I get an "ERROR: Could not decompress archive."
I assume that it's reading the unzip path correctly, "/usr/bin/unzip/" is what I have in singapore.ini, and that's confirmed by my host to be correct.
Thanks for any help.
<edit>
Also... I'm using mysql, so I'm not sure if that affects anything.
Last edited by fotogeek (2006-09-18 22:20:51)
Offline
#9 2006-09-22 20:41:47
- fotogeek
- Member
Re: Fixing zip upload
Can someone clarify for me? I've changed
Code:
$contents = $this->getListing($wd,"images");
to
Code:
$contents = $this->getListing($wd,$this->config->recognised_extensions);
tried it, didn't work.
Then I changed
Code:
$contents = $this->getListing($wd .= '/'.$contents->dirs[0],"images");
to
Code:
$contents = $this->getListing($wd,$this->config->recognised_extensions);
didn't work.
So I thought maybe revert back, and just get rid of the ,"images" in both lines, as the first poster mentioned.
Didn't work.
Am I missing something? Does this just not work with a MySQL database? Where does it put the temp files? Maybe that's not writable or something...
Thanks
Last edited by fotogeek (2006-09-22 20:49:16)
Offline
#10 2006-09-23 06:06:09
- Egypt Urnash
- Member

Re: Fixing zip upload
"Never underestimate the power of printf for debugging."
Try changing the beginning of addMultipleImages() from this...
Code:
//find system temp directory
if(!($systmpdir = $this->findTempDirectory()))
return $this->pushError($this->translator->_g("Unable to find temporary storage space."));
//create new temp directory in system temp dir but stop after 100 attempts
while(!Singapore::mkdir($tmpdir = $systmpdir."/".uniqid("sg")) && $tries++<100);
$archive = $_FILES["sgArchiveFile"]["tmp_name"];
if(!is_uploaded_file($archive))
return $this->pushError($this->translator->_g("Could not upload file."));
//decompress archive to temp
$cmd = escapeshellcmd($this->config->pathto_unzip);
$cmd .= ' -d "'.escapeshellcmd(realpath($tmpdir));
$cmd .= '" "'.escapeshellcmd(realpath($archive)).'"';
if(!exec($cmd))
return $this->pushError($this->translator->_g("Could not decompress archive."));to this:
Code:
//find system temp directory
if(!($systmpdir = $this->findTempDirectory()))
return $this->pushError($this->translator->_g("Unable to find temporary storage space."));
//create new temp directory in system temp dir but stop after 100 attempts
while(!Singapore::mkdir($tmpdir = $systmpdir."/".uniqid("sg")) && $tries++<100);
$archive = $_FILES["sgArchiveFile"]["tmp_name"];
$this->pushMessage("Temp directory is $tmpdir");
if(!is_uploaded_file($archive))
return $this->pushError($this->translator->_g("Could not upload file."));
$this->pushMessage("File is $archive");
//decompress archive to temp
$cmd = escapeshellcmd($this->config->pathto_unzip);
$cmd .= ' -d "'.escapeshellcmd(realpath($tmpdir));
$cmd .= '" "'.escapeshellcmd(realpath($archive)).'"';
$this->pushMessage("Decompression command: $cmd");
if(!exec($cmd,$results)) {
$this->pushError("<pre>".print_r($results,true)."</pre>");
return $this->pushError($this->translator->_g("Could not decompress archive."));}
$this->pushMessage("<pre>".print_r($results,true)."</pre>");- basically, you're sticking a few calls to pushMessage into it, to see what the hell's happening.
When you try to upload an archive, you should see something like
Temp directory is /tmp/sg4514c0295630f
File is /var/tmp/phpDuAgJA
Decompression command: /usr/bin/unzip -d "/private/tmp/sg4514c0295630f" "/private/var/tmp/phpDuAgJA"
Array
(
[0] => Archive: /private/var/tmp/phpDuAgJA
[1] => inflating: /private/tmp/sg4514c0295630f/22.jpg
[2] => creating: /private/tmp/sg4514c0295630f/__MACOSX/
[3] => inflating: /private/tmp/sg4514c0295630f/__MACOSX/._22.jpg
[4] => inflating: /private/tmp/sg4514c0295630f/dc-1.gif
[5] => inflating: /private/tmp/sg4514c0295630f/__MACOSX/._dc-1.gif
[6] => inflating: /private/tmp/sg4514c0295630f/KIRBY-PUNCH-PEGGY.jpeg
[7] => inflating: /private/tmp/sg4514c0295630f/__MACOSX/._KIRBY-PUNCH-PEGGY.jpeg
)
Archive contents added.
If something goes wrong during the unzip, then you'll hopefully see its errors instead...
Offline
#11 2006-09-23 07:49:18
- pavian
- Moderator

Re: Fixing zip upload
Maybe at first you can try and download the maintaince-release (0.10.1) from the front page.
Offline
#12 2007-07-01 20:02:46
- laszlo
- Member
Re: Fixing zip upload
First of all, sorry my poor english. I had a same problem. I searched the findTempDirectory() function in admin.class.php file. I commented out the whole section, and only add this line:
return ini_get('upload_tmp_dir');
The upload_tmp_dir is come from php.ini file. I think this more platform independent sollution. What do you think?
Offline
#13 2007-07-01 20:24:52
- laszlo
- Member
Re: Fixing zip upload
Here is my findTempDirectory function:
Code:
function findTempDirectory()
{
if(isset($_ENV["TMP"]) && is_writable($_ENV["TMP"])) return $_ENV["TMP"];
elseif( is_writable(ini_get('upload_tmp_dir'))) return ini_get('upload_tmp_dir');
elseif(isset($_ENV["TEMP"]) && is_writable($_ENV["TEMP"])) return $_ENV["TEMP"];
elseif(is_writable("/tmp")) return "/tmp";
elseif(is_writable("/windows/temp")) return "/windows/temp";
elseif(is_writable("/winnt/temp")) return "/winnt/temp";
else return null;
}Last edited by laszlo (2007-07-01 20:27:15)
Offline
#14 2007-10-18 07:31:31
- ajaykumar.kataram
- Member
Re: Fixing zip upload
hai all
see the above thread for the zip upload
http://www.sgal.org/forum/viewtopic.php?id=679
it worked
Thanks and regards
Ajay
Offline
#15 2009-12-30 12:13:20
- rozerdemit
- Member
Re: Fixing zip upload
Paul wrote:
There's a list of recognised extensions in singapore.ini (towards the bottom of the file). Maybe the call to this getListing function should incorporate those extensions somehow...?
yes you are right, thanks for suggestion,,,,,
Offline