stualk Posted January 22, 2007 Share Posted January 22, 2007 I pinched the code below from and php scripts site. It's always worked fine but since I moved my site over to a new server with the latest version of PHP it's suddenly stopped working. Can anyone understand why that might be? I've turned register_globals on so it can't be that issue. Here's the error i'm getting and the code is below:"Fatal error: Cannot redeclare scandir() in myurlhere.com/upload_images.php on line 56"[code]<?php $dir = "myurlgoeshere.com/images"; $types = array("image/pjpeg", "image/gif"); //Function to do a directory listingfunction scandir($dirstr) { echo "<pre>\n"; passthru("ls -l -F $dirstr 2>&1 "); echo "</pre>\n";}//Check to determine if the submit button has been pressed if((isset($_POST['submit'])) and ($_POST['PW'] == $pw)){ //Shorten Variables $tmp_name = $_FILES['upload']['tmp_name']; $new_name = $_FILES['upload']['name']; $path = $_POST['subdir']; $fullpath = "$dir$path/"; $fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath))); $clean_name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($new_name) ) ) );// lets see if we are uploading a file or doing a dir listing if(isset($_POST['Dir'])){ echo "Directory listing for $fullpath\n"; scandir("$fullpath"); }else{ //Check MIME Type if ((in_array($_FILES['upload']['type'], $types)) and (!file_exists($fullpath.$clean_name))){ // create a sub-directory if required if (!is_dir($fullpath)){ mkdir("$fullpath", 0755); } //Move file from tmp dir to new location move_uploaded_file($tmp_name,$fullpath . $clean_name); echo "$clean_name of {$_FILES['upload']['size']} bytes was uploaded sucessfully to $fullpath"; }else{ //Print Error Message echo "File <strong><em>{$_FILES['upload']['name']}</em></strong> Was Not Uploaded - bad file type or file already exists<br />"; //Debug $name = $_FILES['upload']['name']; $type = $_FILES['upload']['type']; $size = $_FILES['upload']['size']; $tmp = $_FILES['upload']['name']; echo "Name: $name<br />Type: $type<br />Size: $size<br />Tmp: $tmp"; } } } else { echo 'Ready to upload your file'; } ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/ Share on other sites More sharing options...
JJohnsenDK Posted January 22, 2007 Share Posted January 22, 2007 You are using the function scandir() to scan a string. I think you want to scan the variable like this:if(isset($_POST['Dir'])){ echo "Directory listing for $fullpath\n"; scandir($fullpath);Remove "" from scandir... Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-166314 Share on other sites More sharing options...
redbullmarky Posted January 22, 2007 Share Posted January 22, 2007 JJohnsen, as the $fullpath var is enclosed by double quotes, it should work fine - although unnecessary.taking a guess, you might not have sufficient priveliges set up in your php.ini file that allows running of command line tools:[code] passthru("ls -l -F $dirstr 2>&1 ");[/code]it maybe worth looking at some of PHP's directory/file handling functions to put together a suitable replacement, or changing the setting (the safe_mode ones i think - take a look at [url=http://uk2.php.net/passthru]the manual for passthru[/url]) in your php.ini file to allow access to command line tools like 'ls'cheers Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-166323 Share on other sites More sharing options...
stualk Posted January 22, 2007 Author Share Posted January 22, 2007 Ok, thanks for that. As i'm a bit of a novice and so to avoid me making a stupid mistake, can you tell me roughly what i'm looking for in the php.ini file? I've had a scan through and couldn't find anything to do with command line tools. The links you gave me mentions using the passthru() function in place of exec() or system(). Is that in the php.ini file?I'm confused!By the way, I did try JJohnsen's method and that did stop me from getting the error I was getting previously. The only problem is it then started to give me an error saying "No such file or directory" but the path was correct and the directory does exist, so I was a little confused to say the least! Doesn't take much like...! Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-166442 Share on other sites More sharing options...
stualk Posted January 23, 2007 Author Share Posted January 23, 2007 I'm not sure I need to change any settings in the php.ini file. I made the changes as suggested by JJohnsen above and the upload window half works now. It no longer gives me the error I was getting but when I try to do a directory listing or upload a file I get this error 3 times:Warning: scandir() [function.scandir]: (errno 2): No such file or directory Not too sure why because i've checked and double checked and the directory/path is fine. Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-167030 Share on other sites More sharing options...
redbullmarky Posted January 23, 2007 Share Posted January 23, 2007 after this line:[code] $fullpath = str_replace("..", "", str_replace("\.", "", str_replace("//", "/", $fullpath)));[/code]just put an: echo $fullpath; to display the path, and then double check that the path displayed exists. you could be getting into a bit of a mix with relative/absolute paths. Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-167039 Share on other sites More sharing options...
stualk Posted January 23, 2007 Author Share Posted January 23, 2007 That helped! It turns out the path to the correct folder is slightly different on the new server and I only found out when I displayed the path that was being used. Typical but thanks!The upload is working fine now but there's an option to do a directory listing to see what files have been uploaded to the folder and instead of using the folder that i've specified it's doing a directory listing for the folder that the upload window is in and showing all the database.php pages, etc.Any idea what might be causing that? Quote Link to comment https://forums.phpfreaks.com/topic/35219-image-uploader-has-stopped-working/#findComment-167044 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.