rnb_cassanova Posted March 6, 2008 Share Posted March 6, 2008 hi guys, As you may have seen I have completed the upload facility, i now need to be able to retrieve them from the destination file through the system. Can anyone help with a method? Thanks David Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 Don't understand what you want. Do you want to view all the picture in the directory now??? Quote Link to comment Share on other sites More sharing options...
phpanon Posted March 6, 2008 Share Posted March 6, 2008 how did u upload the files? I take it you moved the files into a created folder.. but have u saved the location of them into a database>!? Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 i have a target folder where the users uploads defaults to but now i want to be able to see whats in that folder, but only that folder, so in essence the best way i can describe is something like this... http://esupport.epson-europe.com/ProductHome.aspx?lng=en-GB&data=dkmEK02SU002FeroarA05EEv55UIF0kgE0cfqxevtXS8ndgU003D&tc=6#7 all of the files in one place, constantly updated and the user can download. I hope im making sense, Cheers David Quote Link to comment Share on other sites More sharing options...
almystersv Posted March 6, 2008 Share Posted March 6, 2008 surely what you want is nothing like the example epsom page you gave. Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 You would need to loop through the directory and create links. <?php $dir = "path/to/dir"; if ($handle = opendir($dir)) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if($file != ".." && $file != "."){ echo '<a href="'.$dir.$file.'" target="_blank" border=0>'.$file.'</a><br />'; } } } ?> This will just create links. Ray ?> Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 Hi, im currently getting the following error Warning: opendir(/Uploads) [function.opendir]: failed to open dir: No error in C:\wamp\www\DV8 System\TargetUploadsPage.php on line 3 I have changed the target directory, but am leaving something out. the file is within the root and called \uploads Cheers lads david Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 the directory either has to be linked from where the script is being run from or use the absolute path $dir = "C:/wamp/www/uploads/"; or if I am reading correctly $dir = "../uploads/"; the .. at the beginning will make the script go back one directory to the root then open the uploads directory i know I forgot it in my last post but don't forget to add the slash in the link echo '<a href="'.$dir."/".$file.'" target="_blank" border=0>'.$file.'</a><br />'; Ray Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 fantastic, it reads from the file correctly but when i click the link, I am not given the option of saving the file but instead an error that says Firefox cannot open the file. How can i rectify this, thanks for your help lads. David Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 sorry forgot to say, also if i 'save target as' it will not download also. Cheers david Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 it all depends on what kind of files they are. What type we talking about here. Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 it will be image files, so JPEG, BMP, GIF and PNG's i believe. any ideas? cheers david Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 what is the code you are using now?? Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 the one you sent me the - <?php $dir = "C:/wamp/www/DV8 System/uploads"; if ($handle = opendir($dir)) { /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if($file != ".." && $file != "."){ echo '<a href="'.$dir."/".$file.'" target="_blank" border=0>'.$file.''; } } } ?> Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 ok when I posted it I forgot to use the code tags so the end got cut off. Also changed it to use double quotes so you can put the line break at the end echo "<a href=\"".$dir."/".$file."\" target=\"_blank\" border=0>$file</a><br>\n"; Ray Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 no cigar mate, im getting this error... http://i32.photobucket.com/albums/d36/B_318is/error-upload.jpg and on IE the link is dead. Cheers david Quote Link to comment Share on other sites More sharing options...
craygo Posted March 6, 2008 Share Posted March 6, 2008 OK the problem is using the absolute path in the link to the picture. so you have to change the $dir to the relative path. $dir = "uploads"; Ray Quote Link to comment Share on other sites More sharing options...
thezaphod042 Posted March 6, 2008 Share Posted March 6, 2008 rmb, Also here is the simple code I use to do the same thing... <?php $dn = opendir (wowadd); $exclude = array("index.php", ".", "..", "download.php", "download.html", "download.php"); // adiciona os arquivos ao array $arquivos while($fn = readdir($dn)) { if ($fn == $exclude[0] || $fn == $exclude[1] || $fn == $exclude[2] || $fn == $exclude[3] || $fn == $exclude[4] || $fn == $exclude[5]) continue; $arquivos[] = $fn; } // ordena o vetor sort($arquivos); // exibe os arquivos foreach ($arquivos as $arquivo) if (is_dir($arquivo)){ $dir .= "<img src='/wow.png'> <a href='$arquivo'>$arquivo</a><br>"; }else{ $tamanho = filesize($arquivo); $m = 'bytes'; if ($tamanho>1024) { $tamanho=round($tamanho/1024,2); $m = 'KB'; } elseif($tamanho > 1024*1024){ $tamanho = round(($tamanho/1024)/1024,2); $m = 'MB'; } $arq .= "<img src='../wow.png'> <a href='$arquivo'>$arquivo</a> - $tamanho $m<br>"; } echo $dir . $arq; closedir($dn); ?> currently it is set to the directory WOWADD which is in the same root folder as the calling script. Now if you figure out a way to have variable passed to this to change directories based on selection in the submiting form please let me know... drop me a note at thezaphod04 AT gmail DOT com and we can comlaborate some.. Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 hi, i inserted that to recieve the error- <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-3803417-1"; urchinTracker(); </script> im a bit lost now. if you can help i would appreciate it? Cheers David Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 hi im sorry, it worked perfect my fault. thanks for all your help Ray. Solved. Cheers David Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.