Note that there are some explanatory texts on larger screens.

plurals
  1. POMy script is not displaying links properly
    primarykey
    data
    text
    <p>It's gonna be hard for me to explain the whole situation, but I'll try...</p> <p>I made a script for my image host that unZips a Zip package with images in it to a certain location, renames the files to a random file name and outputs multiple links to the images. The last part is not working properly! I am unable to output multiple links to the images - It simply outputs one link to the image (the first one) and the rest is in the uploaded folder, but not listed as a link.</p> <p>Same goes with generating a thumbnail for the just renamed images. Only one thumbnail is generated for the first image, and the rest of the images if being ignored.</p> <p>This is how my code looks like:</p> <pre><code>&lt;?php session_start(); include('includes/imgit.class.php'); $IMGit = new imgit(); /** * @ignore */ if (!defined('IN_IMGIT')) { exit; } $IMGit-&gt;error_report(true); $IMGit-&gt;disable(false); $IMGit-&gt;ieNote(true); if (isset($_POST['zipsent']) || $_POST['zipsent'] == true &amp;&amp; isset($_FILES['archive'])) { if ($_FILES['archive']['size'] &lt;= MAX_ZIPSIZE) { // Main variables $key = $IMGit-&gt;random_key(10); $move_zip = move_uploaded_file($_FILES['archive']['tmp_name'], ZIP_PATH . $key . $_FILES['archive']['name']); $zip = ZIP_PATH . $key . $_FILES['archive']['name']; $extension = substr($zip, -3); $filename = $IMGit-&gt;zipContent($zip); // array $url = str_replace('www.', '', $IMGit-&gt;generate_site_url()); // ZIP limit is 100 images if (sizeof($filename) &lt;= 100) { // Only ZIP archives if ($extension == 'zip') { if ($filename) { foreach($filename as $key =&gt; $value) { // Get extension $image_extension = substr($value, -3); $image_extension = (strtoupper($image_extension)) ? strtolower($image_extension) : $image_extension; $image_extRule = $image_extension == JPG || $image_extension == JPEG || $image_extension == GIF || $image_extension == PNG || $image_extension == BMP || $image_extension == ICO; if ($image_extRule) { // Set variables and do some processing $unZip = $IMGit-&gt;unZip($zip, IMAGES_PATH); $url = str_replace('www.', '', $IMGit-&gt;generate_site_url()); $image_name = $IMGit-&gt;random_key(7) . $value; $image_name = (strpos($image_name, ' ') !== false) ? str_replace(' ', '', $image_name) : $image_name; if (file_exists(IMAGES_PATH . $filename[$key])) { // Rename extracted files $rename = rename(IMAGES_PATH . $filename[$key], IMAGES_PATH . $image_name); if ($rename &amp;&amp; file_exists($zip) &amp;&amp; sizeof($image_name)) { // Delete ZIP unlink($zip); // Set URL variables $image_urls = $url . IMAGES_PATH . $image_name; $image = IMAGES_PATH . $image_name; // Generate a thumbnail $IMGit-&gt;generate_thumbnail($image_urls, $image_name, THUMBNAIL_SIZE, THUMBNAIL_SIZE, true, 'file', false, false, THUMBS_PATH); $thumb_urls = $url . THUMBS_PATH . $image_name; $filename[] = array('direct' =&gt; $image_urls, 'thumb' =&gt; $thumb_urls); } } } } } } } } } else { header('Location: index.php'); } include('includes/header.php'); { if ($_FILES['archive']['size'] &gt; MAX_ZIPSIZE) { echo '&lt;span id="home-info"&gt;The ZIP archive is bigger than 100 MB.&lt;/span&gt;'; } else if ($extension != 'zip') { echo '&lt;span id="home-info"&gt;Only ZIP archives are upload ready.&lt;/span&gt;'; } else if (sizeof($filename) &gt; 100) { echo '&lt;span id="home-info"&gt;The number of the images inside the archive was more than 100.&lt;/span&gt;'; } else if (!$image_extRule) { echo '&lt;span id="home-info"&gt;The extensions inside the ZIP did not match our allowed extension list.&lt;/span&gt;'; unlink($zip); } // unlink zip if failed else { echo '&lt;span id="home-info"&gt;Image(s) was/were successfully uploaded!&lt;/span&gt;'; } } ?&gt; &lt;/div&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;a href="index.php"&gt;&lt;img src="css/images/site-logo.jpg" id="logo" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/div&gt; &lt;div id="box"&gt; &lt;?php global $filename, $image_urls, $thumb_urls; echo '&lt;br /&gt;'; echo '&lt;div id="links"&gt;'; echo '&lt;table&gt;'; echo LINKS_DIRECT; for($i = 0; $i &lt; sizeof($filename); $i++) { echo $filename[$i]['direct'] . "\n"; } echo LINKS_CLOSE; echo LINKS_THUMB; for($i = 0; $i &lt; sizeof($filename); $i++) { echo $filename[$i]['thumb'] . "\n"; } echo LINKS_CLOSE; echo LINKS_BBCODE; for($i = 0; $i &lt; sizeof($filename); $i++) { echo '[IMG]' . $filename[$i]['direct'] . '[/IMG]' . "\n"; } echo LINKS_CLOSE; echo LINKS_HTML; for($i = 0; $i &lt; sizeof($filename); $i++) { echo '&lt;a href="' . $filename[$i]['direct'] . '"&gt;&lt;img src="' . $filename[$i]['thumb'] . '" /&gt;&lt;/a&gt;' . "\n"; } echo LINKS_CLOSE; echo '&lt;/table&gt;'; echo '&lt;br /&gt;'; echo '&lt;input type="reset" id="resetbtn-remote" class="button-sub" value="&amp;laquo; Upload more" /&gt;'; echo '&lt;br /&gt;'; echo '&lt;/div&gt;'; ?&gt; &lt;/div&gt; &lt;?php include('includes/footer.php'); ?&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I guess the problem is inside the foreach loop (it was a for loop a few days ago, but faced the same problems), but I can't seem to fix it. I'll reexplain in a short version:</p> <ul> <li>I upload a Zip archive</li> <li>Script unZips the archive</li> <li>Script renames the extracted files</li> <li>Thumbnail must be generated for all images that were in the Zip (fails)</li> <li>Multiple links should be outputted matching every image the was in the Zip (fails)</li> </ul> <p>Ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload