KANAYO AUSTIN KANE KANAYO AUSTIN KANE - 3 months ago 11
PHP Question

Uploaded images not displaying

I am running a php code for multiple image upload and its working fine on my WAMP local server and the images displays when echoed out:

<?php

if(is_array($_FILES))
{
foreach ($_FILES['files']['name'] as $name => $value)
{
$file_name = explode(".", $_FILES['files']['name'][$name]);
$allowed_ext = array("jpg", "jpeg", "png", "gif");
if(in_array($file_name[1], $allowed_ext))
{
$new_name = substr(sha1(mt_rand()),0,50) . '.' . $file_name[1];
$sourcePath = $_FILES['files']['tmp_name'][$name];
$target = "photos/".$new_name;
if(move_uploaded_file($sourcePath, $target))
{
echo "<img src='".$target."' />";
}
}
}
}

?>


But when I uploaded it to my website, the images are being uploaded to the photos folder but the images doesn't echo out.

This is a screenshot of my WAMP local server:
This is a screenshot of my WAMP local server:

And here is for my website:
And here is for my website

Answer

I have figured out my mistake, the code above doesn't correspond with my website code I don't know how but I had a slight error like this

$allowed_ext = array("jpg". "jpeg", "png", "gif"); 

And I am uploading it through the jQuery $.ajax so I can't get any error directly from my php page

Comments